我正在使用两个组合框,从组合框1中选择数据后,我想在COmbo框2中显示数据. [英] I am using two Combo Boxs where i want to show data in COmbo box 2 after selecting data from combo box 1.

查看:130
本文介绍了我正在使用两个组合框,从组合框1中选择数据后,我想在COmbo框2中显示数据.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用两个组合框,从组合框1中选择数据后,我想在组合框2中显示数据.

请帮助
例如

组合框1个数据

a
b
c
d

组合框2的数据类似于我选择a,b,c或d的情况

用于选择收件箱1

1
2
3

用于在框1中选择b

4
5
6等.

我在Excel中有两张纸,一张纸包含组合框1数据,即. a b c& amp; d
第二页包含组合框2的数据,如下所示

1
一个2
3
b 4
b 5
b 6
等等
请帮助

I am using two Combo Boxs where i want to show data in COmbo box 2 after selecting data from combo box 1.

please help
e.g.

combo box 1 data

a
b
c
d

combo box 2 data shld be like if i select a, b, c , or d

for selecting a in box 1

1
2
3

for selecting b in box 1

4
5
6 and so on.

i have two sheets in excel one sheets contain combo box 1 data ie. a b c & d
and seceond sheet contains combo box 2 data like below

a 1
a 2
a 3
b 4
b 5
b 6
and so on
please help

推荐答案

您好,YuDi Sri,
希望这会有所帮助

使用两个工作表Sheet1和Sheet2
和2个组合框CBox1和CBox2

私人子UserForm_Initialize()
工作表("Sheet1").激活
如果WorksheetFunction.CountA(Cells)> 0然后
''以获取工作表1中使用的总行数
sv_Sheet1RowCount = Cells.Find(What:="*",After:= [A1],SearchOrder:= xlByRows,SearchDirection:= xlPrevious).Row
如果结束
如果sv_Sheet1RowCount> 1然后
CBox1.Clear
对于Rowi = 1到sv_Sheet1RowCount
CBox1.AddItem工作表("Sheet1").Cells(Rowi,1).Value
下一个
如果结束
结束子

专用子CBox1_Change()
工作表("Sheet2").激活
如果WorksheetFunction.CountA(Cells)> 0然后
''以获取工作表2中已使用的总行数
sv_Sheet2RowCount = Cells.Find(What:="*",After:= [A1],SearchOrder:= xlByRows,SearchDirection:= xlPrevious).Row
如果结束

如果sv_Sheet2RowCount> 1和CBox1.Value<> "然后
CBox2.Clear''清除组合框2以避免附加
对于Rowi = 1到sv_Sheet2RowCount
如果UCase(CBox1.Value)= UCase(Worksheets("Sheet2").Cells(Rowi,1).Value)然后
CBox2.AddItem工作表("Sheet2").Cells(Rowi,2).Value
如果结束
下一个
如果结束
结束Sub
Hi YuDi Sri,
Hope this helps

Use two sheet Sheet1 and Sheet2
and 2 Combo box CBox1 and CBox2

Private Sub UserForm_Initialize()
Worksheets("Sheet1").Activate
If WorksheetFunction.CountA(Cells) > 0 Then
'' to fetch the total used row''s in sheet 1
sv_Sheet1RowCount = Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
End If
If sv_Sheet1RowCount > 1 Then
CBox1.Clear
For Rowi = 1 To sv_Sheet1RowCount
CBox1.AddItem Worksheets("Sheet1").Cells(Rowi, 1).Value
Next
End If
End Sub

Private Sub CBox1_Change()
Worksheets("Sheet2").Activate
If WorksheetFunction.CountA(Cells) > 0 Then
'' to fetch the total used row''s in sheet 2
sv_Sheet2RowCount = Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
End If

If sv_Sheet2RowCount > 1 And CBox1.Value <> "" Then
CBox2.Clear '' clearing the combobox 2 to avoid appending
For Rowi = 1 To sv_Sheet2RowCount
If UCase(CBox1.Value) = UCase(Worksheets("Sheet2").Cells(Rowi, 1).Value) Then
CBox2.AddItem Worksheets("Sheet2").Cells(Rowi, 2).Value
End If
Next
End If
End Sub


这篇关于我正在使用两个组合框,从组合框1中选择数据后,我想在COmbo框2中显示数据.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆