Linked ComboBox and Duplicate Category removal

johnkykong

New Member
Joined
Aug 30, 2017
Messages
3
Hi everybody. I am some issues with two pieces of an excel sheet, dealing with a userform.

I currently have two comboboxes. Combo Box 1 is designed to pull category matches. I'm using a combobox here so people can type in A (to autofill) and not have to know all of the categories.

So column A has a ton of categories like "Animal" "Car" "Human" and about 15 other categories. Many of which are duplicated as it is the initial filter. I'd like for the duplicates in this initial filter to not show.

I also need the second combo box to pull only the associated items from the filter in combobox1.

Animal Dog
Food. Banana
Car. Silverado
Human. George
Animal. Cat

When Combobox 1 shows Animal, I only want the items in that category to be selectable for Combo box 2. So the drop-down box for combobox2 would show Dog/Cat in that example.

The problem is that there will be too many categories in column A to make individual association filters. So I'm trying to figure out how to make a parent/child relationship with comboboxes, that can change dynamically. I'm also trying to make the category filter box not show duplicates (not show animal twice in this example).

I've tried to repurpose a few items from other posts... but I think I'm having trouble understanding the underlying code to make Box 1 populate Box 2, without having to make stipulations for *each* category.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
So here is pretty much what I'm working with at the moment. The textbox drives the combobox1 categories. But I can't get combobox 2 to recognize combobox 1 as a base filter.


Option Compare Text
Sub Optioncomparetext ()
Dim rCell as Range
For each rCell in Range ("A1:A100")
If rCell = "CAT" Then
MsgBox rCell.Address & " has " & rCell & " in it"
End If
Next rCell
End Sub

Private Sub Textbox1_Change ( )
Dim ring As Range, e
With Me
.ComboBox1.Clear
If Len (.TextBox1.Value) Then
For Each e In Sheets("Database").Cells(1).CurrentRegion.columns(1).Value
If (e <> "") * (e Like "*" & .TextBox1.Value & "*") then
.Combobox1.Additem e
End if
Next
With .Combobox1
If .listcount > 0 then .listened = 0
End with
End if
End with
End Sub

Private_sub commandbutton1_click()
Row_number = 0
Do
DoEvents
Row_number = row_number +1
Item_in_review = Sheets("Database").Range("A" & row_number)
If item_in_review = ComboBox2.Text then
Textbox2.Text = Sheets("Database").Range("B" & row_number)
Textbox11.Text = Sheets("Database").Range("C" & row_number)
Textbox20.Text = Sheets("Database").Range("D" & row_number)
End if
Loop until item_in_review = ""

End Sub
 
Upvote 0
I got the linked boxes to work, it was definitely an issue of me not understanding the code.

The Textbox search linking to ComboBox1 is still yielding duplicates lines, though. The problem lies with the Textbox1 private sub.
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,885
Members
452,364
Latest member
springate

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