Here is the data sample:
Not sure what i am doing wrong. I cant seem to populate the 3rd combo box. Below is my code;
Option Explicit
Public enableevents As Boolean
Dim sh As Worksheet
Private Sub UserForm_Activate()
Set sh = ThisWorkbook.Sheets("DropDowns")
Dim i As Long
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
cboMainCat.AddItem sh.Range("B" & i)
End If
Next i
End Sub
Private Sub cboMainCat_Change()
Dim i As Long
cboCat.Clear
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 = "Cat" And sh.Range("C" & i).Value = cboMainCat.Value Then
cboCat.AddItem sh.Range("B" & i)
End If
Next i
End Sub
Private Sub cboCat_Change()
Dim i As Long
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" And sh.Range("C" & i).Value = cboCat.Value Then
cboSubCat.AddItem sh.Range("B" & i)
End If
Next i
End Sub
Drop-Downs (col A) | Items (col B) | Parent DropDown(col C) |
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 | Tolls | Vehicle |
Cat | Taxes | Vehicle |
Cat | Road Trip | Entertainment |
Cat | Local Activities | Entertainment |
Cat | Kevin | Personal |
Cat | Saru | Personal |
Cat | Pet | Personal |
Cat | Saru | Medical |
Cat | Kevin | Dental |
Cat | Saru | Dental |
Cat | Kevin | Vision |
Cat | Saru | Vision |
Sub Category | Electric | Utilities |
Sub Category | Water | Utilities |
Not sure what i am doing wrong. I cant seem to populate the 3rd combo box. Below is my code;
Option Explicit
Public enableevents As Boolean
Dim sh As Worksheet
Private Sub UserForm_Activate()
Set sh = ThisWorkbook.Sheets("DropDowns")
Dim i As Long
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
cboMainCat.AddItem sh.Range("B" & i)
End If
Next i
End Sub
Private Sub cboMainCat_Change()
Dim i As Long
cboCat.Clear
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 = "Cat" And sh.Range("C" & i).Value = cboMainCat.Value Then
cboCat.AddItem sh.Range("B" & i)
End If
Next i
End Sub
Private Sub cboCat_Change()
Dim i As Long
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" And sh.Range("C" & i).Value = cboCat.Value Then
cboSubCat.AddItem sh.Range("B" & i)
End If
Next i
End Sub