3 Dependent Combo Box

Saru

New Member
Joined
May 15, 2020
Messages
19
Office Version
  1. 365
Platform
  1. Windows
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:
Drop-DownsItemsParent DropDown
Main_CatHouse
Main_CatFood
Main_CatVehicle
Main_CatEntertainment
Main_CatPersonal
Main_CatMedical
Main_CatDental
Main_CatVision
CatUtilitiesHouse
CatHousehold_ItemsHouse
CatMaintenanceHouse
CatPaymentHouse
CatInsuraceHouse
CatTaxesHouse
CatMiscHouse
CatGroceriesFood
CatDiningFood
CatPaymentVehicle
CatFuelVehicle
CatInsuranceVehicle
CatTollsVehicle
CatTaxesVehicle
CatRoadside AssistanceVehicle
CatMembershipVehicle
CatRMVVehicle
CatMiscVehicle
CatRoad TripEntertainment
CatVacationEntertainment
CatLocal ActivitiesEntertainment
CatKevinPersonal
CatSaruPersonal
CatPetPersonal
CatIncome TaxPersonal
CatKevinMedical
CatSaruMedical
CatKevinDental
CatSaruDental
CatKevinVision
CatSaruVision
Sub CategoryElectricUtilities
Sub CategoryWaterUtilities
Sub CategoryTrashUtilities
Sub CategorySewerUtilities
Sub CategoryFuelUtilities
Sub CategoryOtherUtilities
Sub CategoryLaundryHousehold_Items
Sub CategoryAppliancesHousehold_Items
 
The cells in col A that have "Sub Category" also have a carriage return, so it cannot find a match.
Remove the carriage return.
 
Upvote 0

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
1590006596954.png


As Fluff comments, edit cell A41, you will notice that you have a character, delete that character and copy cell A41 down.

If you need that character, I think not, let me know to make a small adjustment to the macro
 

Attachments

  • 1590006463130.png
    1590006463130.png
    8.5 KB · Views: 5
Upvote 0
I used Trim function to clear spaces in the dropdown worksheet and tested. It is still not working. Here is the link to the updated file loaded;
 
Upvote 0
It is not a space, so trim does not remove it, it is a control character. You must do as I explained, edit the cell and delete the character on the right side, or easier, retype:
Sub Category

and copy it down.
 
Upvote 0
Thank you DanteAmor! I cant believe the extra space kicked my a** this long. Thank you so much for your support and patience. Greatly appreciated.
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,027
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top