Aretradeser
Board Regular
- Joined
- Jan 16, 2013
- Messages
- 176
- Office Version
- 2013
- Platform
- Windows
Through a UserForm, I perform data searches in a given Excel sheet. This UserForm, among others, has three ComboBoxes:
ComboBox1, select countries.
ComboBox2, dependent on ComboBox1, selects cities belonging to the country we have chosen in ComboBox1.
ComboBox3, selects names.
CODES:
I need the ComboBox3 to be dependent on ComboBox1 and ComboBox2; but I can't find the code that allows it.
ComboBox1, select countries.
ComboBox2, dependent on ComboBox1, selects cities belonging to the country we have chosen in ComboBox1.
ComboBox3, selects names.
CODES:
Rich (BB code):
'
Dim dar As Object
Dim va, vb, vc
Dim n As Integer
'
Private Sub ComboBox1_Enter()
Dim x
dar.Clear
For Each x In va
If Not dar.Contains(x) Then dar.Add CStr(x)
Next
dar.Sort
ComboBox1.List = dar.toArray()
End Sub
'
Private Sub ComboBox2_Enter()
Dim i As Long, tx As String
dar.Clear: tx = UCase(ComboBox1)
For i = LBound(va) To UBound(va)
If UCase(va(i, 1)) = tx Then
If Not dar.Contains(vb(i, 1)) Then dar.Add vb(i, 1)
End If
Next
dar.Sort
ComboBox2.List = dar.toArray()
End Sub
'
Private Sub ComboBox3_Enter()
Dim x
dar.Clear
For Each x In vc
If Not dar.Contains(x) Then dar.Add CStr(x)
Next
dar.Sort
ComboBox3.List = dar.toArray()
End Sub
'
Private Sub UserForm_Initialize()
With Sheets("BDATOS")
n = .Range("B" & Rows.Count).End(xlUp).Row
va = .Range("G2:G" & n) 'ComboBox1 = By country of destination
vb = .Range("H2:H" & n) 'ComboBox2 = By destination city
vc = .Range("B2:B" & n) 'ComboBox3 = By name
End With
Set dar = CreateObject("System.Collections.Arraylist")
End Sub
'
I need the ComboBox3 to be dependent on ComboBox1 and ComboBox2; but I can't find the code that allows it.