Using Combobox for a Dropdown list on a Userform

andrewb90

Well-known Member
Joined
Dec 16, 2009
Messages
1,077
Hi all,

I've been looking up how to do this online, and I haven't had much success, so hopefully someone can point me in the right direction.

I am trying to create a few drop down boxes on a userform, and am trying to make the values a range from my sheet. The three drop downs will be for Month, Day, and Year.
Is there a simple way to do this, that I just haven't found yet?
 
Last edited:

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Hi andrewb90 :)

You can fill a combobox with a list range using the following code:

Code:
Dim c As Range
ComboBox1.Clear 'make sure this is the right combobox name
With Worksheets("(SHEETNAME)") 'change this to your sheets name
    For Each c In .Range(.Range("LISTRANGE"), .Range("A" & .Rows.Count).End(xlUp)) 'replace LISTRANGE with your list's range, I,e. ("A1:A10")
        If c.Value <> vbNullString Then ComboBox1.AddItem c.Value 'Again make sure this is the right combobox name
    Next c
End With
End Sub

Just be sure to change the SHEETNAME to your own name, and make sure ComboBox1 is the one you want to populate.

This code will also remove all the blanks from the bottom of the list, so all you need to do to update it is add items to your spreadsheet and they'll be populated in the combobox once refreshed :)
 
Upvote 0
You said:
I am trying to create a few drop down boxes

I assume you mean Combobox is that correct?

So tell me the name of these three comboboxes
And get values loaded into the combobox from what range?

Give specific details like from column 1 or column 2
Do not say column Month
 
Upvote 0
To load a combobox with values from the active sheet column A
Put this script in your Userform.
The combobox will be loaded with values when you open your userform
Change Combobox name to your needs.
Code:
Private Sub UserForm_Initialize()
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
ComboBox1.List = Range("A1:A" & Lastrow).Value
End Sub
 
Upvote 0
Can I use a named range for each combo box?
Combobox1 would have a list from range "MONTHS"
Combobox2 would have a list from range "DAYS"
Combobox3 would have a list from range "YEARS"

Additionally, the location of the named range in the workbook wouldn't matter right?
 
Upvote 0
Do it like this:
Just so the named Range is in the active Workbook
Code:
Private Sub UserForm_Initialize()
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
ComboBox1.List = Range("MONTHS").Value
ComboBox2.List = Range("DAYS").Value
ComboBox3.List = Range("YEARS").Value
End Sub
 
Upvote 0
I'm getting an error, and I can't tell what's causing it.
Run Time error 104: Method 'Range' of Object'_global' failed
 
Upvote 0
This part of the script is very basic
I suspect your range is not named exactly correct.

Or change
ComboBox2
to:
Combobox



B or b<strike>
</strike>
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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