UserForm combobox VBA drop down list

andrewb90

Well-known Member
JoinedDec 16, 2009Messages1,075
  • Apr 17, 2018
  • #1
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: Apr 17, 2018
C

CheekyDevil

New Member
JoinedApr 15, 2018Messages20
  • Apr 17, 2018
  • #2
Hi andrewb90

My Aswer Is This

Well-known Member
JoinedJul 5, 2014Messages18,171Office Version
  1. 2013
Platform
  1. Windows
  • Apr 17, 2018
  • #3
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

My Aswer Is This

Well-known Member
JoinedJul 5, 2014Messages18,171Office Version
  1. 2013
Platform
  1. Windows
  • Apr 17, 2018
  • #4
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

andrewb90

Well-known Member
JoinedDec 16, 2009Messages1,075
  • Apr 17, 2018
  • #5

ADVERTISEMENT

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?

My Aswer Is This

Well-known Member
JoinedJul 5, 2014Messages18,171Office Version
  1. 2013
Platform
  1. Windows
  • Apr 17, 2018
  • #6
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

andrewb90

Well-known Member
JoinedDec 16, 2009Messages1,075
  • Apr 17, 2018
  • #7
I'm getting an error, and I can't tell what's causing it.
Run Time error 104: Method 'Range' of Object'_global' failed

My Aswer Is This

Well-known Member
JoinedJul 5, 2014Messages18,171Office Version
  1. 2013
Platform
  1. Windows
  • Apr 18, 2018
  • #8
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

Video liên quan

Chủ Đề