Click here to Skip to main content
15,887,328 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

1 solution

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
 
Share this answer
 
v2
Comments
YuDi Sri 21-Nov-11 4:28am    
Thanks a lot really helps me :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900