Adding drop down menu to a user form

Man, you're typin' too fast for me! :LOL:

Let me see if I got this.
You have a list of colors, some primary and some that're "Fuscia or those fancy colors", and you want only those in your list that have the word "Primary" in another column of their row to appear in your combobox's dropdown list?

If that's right then which column are your colors in and which column would have "primary" in it?
 
Upvote 0

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
OK, try this and see if it helps.
Open the VBE and show your userform.
Right click it and choose View code.
Paste this into the userform's code module (The large white area on the right.)
Code:
Private Sub UserForm_Activate()
Dim LstRw As Long
'Determine the length of your list
LstRw = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
For x = 1 To LstRw
    If Cells(x, 2) = "" Then _
        Me.ComboBox1.AddItem (Range("A" & x).Value)
Next x
End Sub
Now, you MUST make sure the RowSource property is left blank.
Then press Alt+Q to quit the VBE and get back to your sheet. Now you can experiment with adding / deleting values in column B to see what it does to your combobox list when you call the userform.

Is that what you're looking for?
 
Upvote 0
Looks like it could work. I suppose I should have mentioned the information is coming frmo column B instead. How would I change the above code to reflect that?
 
Upvote 0
So... you want column B to get loaded into your combobox, only if what column is blank?
 
Upvote 0
That only takes a few minor changes.
Here you go...
Code:
Private Sub UserForm_Activate()
Dim LstRw As Long
'Determine the length of your list
LstRw = Sheets("Sheet1").Cells(Rows.Count, 2).End(xlUp).Row
For x = 1 To LstRw
    If Cells(x, 13) = "" Then _
        Me.ComboBox1.AddItem (Range("B" & x).Value)
Next x
End Sub
 
Upvote 0
Excellent! Worked like a charm! Thank you kindly! Now how do I get it to ignore blanks? For some reason I have blanks in my list.
 
Upvote 0
You're most welcome.
This will test for blanks in column B and ignore them.
Code:
Private Sub UserForm_Activate()
Dim LstRw As Long
'Determine the length of your list
LstRw = Sheets("Sheet1").Cells(Rows.Count, 2).End(xlUp).Row
For x = 1 To LstRw
    If Cells(x, 2) <> "" And Cells(x, 13) = "" Then _
        Me.ComboBox1.AddItem (Cells(x, 2).Value)
Next x
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,491
Messages
6,125,104
Members
449,205
Latest member
ralemanygarcia

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