I have three dependent combo box
I am populating first 'cboMainCat' on form activation. The two remaining (cboCat & cboSubCat) i am trying to populate on change event.
second one works fine but the third i am having trouble seeing what i am doing i can seem to populate the values.
First:
Private Sub UserForm_Activate()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("DropDowns")
Dim i As Integer
Me.cboMainCat.Clear
For i = 2 To sh.Range("A" & Application.Rows.Count).End(xlUp).Row ' becoz 1 is the header
If sh.Range("A" & i).Value = "Main_Cat" Then
Me.cboMainCat.AddItem sh.Range("B" & i)
End If
Next i
End Sub
Second:
Private Sub cboMainCat_Change()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("DropDowns")
Dim i As Integer
Me.cboCat.Clear
For i = 2 To sh.Range("A" & Application.Rows.Count).End(xlUp).Row ' becoz 1 is the header
If sh.Range("A" & i).Value = "Cat" Then
If sh.Range("C" & i).Value = Me.cboMainCat.Value Then
Me.cboCat.AddItem sh.Range("B" & i)
End If
End If
Next i
End Sub
Third:
Private Sub cboCat_Change()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("DropDowns")
Dim i As Integer
Me.cboSubCat.Clear
For i = 2 To sh.Range("A" & Application.Rows.Count).End(xlUp).Row ' becoz 1 is the header
If sh.Range("A" & i).Value = "Sub Category" Then
If sh.Range("C" & i).Value = Me.cboCat.Value Then
Me.cboSubCat.AddItem sh.Range("B" & i)
End If
End If
Next i
End Sub
My Data in an excel sheet:
I am populating first 'cboMainCat' on form activation. The two remaining (cboCat & cboSubCat) i am trying to populate on change event.
second one works fine but the third i am having trouble seeing what i am doing i can seem to populate the values.
First:
Private Sub UserForm_Activate()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("DropDowns")
Dim i As Integer
Me.cboMainCat.Clear
For i = 2 To sh.Range("A" & Application.Rows.Count).End(xlUp).Row ' becoz 1 is the header
If sh.Range("A" & i).Value = "Main_Cat" Then
Me.cboMainCat.AddItem sh.Range("B" & i)
End If
Next i
End Sub
Second:
Private Sub cboMainCat_Change()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("DropDowns")
Dim i As Integer
Me.cboCat.Clear
For i = 2 To sh.Range("A" & Application.Rows.Count).End(xlUp).Row ' becoz 1 is the header
If sh.Range("A" & i).Value = "Cat" Then
If sh.Range("C" & i).Value = Me.cboMainCat.Value Then
Me.cboCat.AddItem sh.Range("B" & i)
End If
End If
Next i
End Sub
Third:
Private Sub cboCat_Change()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("DropDowns")
Dim i As Integer
Me.cboSubCat.Clear
For i = 2 To sh.Range("A" & Application.Rows.Count).End(xlUp).Row ' becoz 1 is the header
If sh.Range("A" & i).Value = "Sub Category" Then
If sh.Range("C" & i).Value = Me.cboCat.Value Then
Me.cboSubCat.AddItem sh.Range("B" & i)
End If
End If
Next i
End Sub
My Data in an excel sheet:
Drop-Downs | Items | Parent DropDown |
Main_Cat | House | |
Main_Cat | Food | |
Main_Cat | Vehicle | |
Main_Cat | Entertainment | |
Main_Cat | Personal | |
Main_Cat | Medical | |
Main_Cat | Dental | |
Main_Cat | Vision | |
Cat | Utilities | House |
Cat | Household_Items | House |
Cat | Maintenance | House |
Cat | Payment | House |
Cat | Insurace | House |
Cat | Taxes | House |
Cat | Misc | House |
Cat | Groceries | Food |
Cat | Dining | Food |
Cat | Payment | Vehicle |
Cat | Fuel | Vehicle |
Cat | Insurance | Vehicle |
Cat | Tolls | Vehicle |
Cat | Taxes | Vehicle |
Cat | Roadside Assistance | Vehicle |
Cat | Membership | Vehicle |
Cat | RMV | Vehicle |
Cat | Misc | Vehicle |
Cat | Road Trip | Entertainment |
Cat | Vacation | Entertainment |
Cat | Local Activities | Entertainment |
Cat | Kevin | Personal |
Cat | Saru | Personal |
Cat | Pet | Personal |
Cat | Income Tax | Personal |
Cat | Kevin | Medical |
Cat | Saru | Medical |
Cat | Kevin | Dental |
Cat | Saru | Dental |
Cat | Kevin | Vision |
Cat | Saru | Vision |
Sub Category | Electric | Utilities |
Sub Category | Water | Utilities |
Sub Category | Trash | Utilities |
Sub Category | Sewer | Utilities |
Sub Category | Fuel | Utilities |
Sub Category | Other | Utilities |
Sub Category | Laundry | Household_Items |
Sub Category | Appliances | Household_Items |