Question re: VBA ComboBox with many items

leopardhawk

Well-known Member
Joined
May 31, 2007
Messages
611
Office Version
  1. 2016
Platform
  1. Windows
Hello forum friends, can anyone suggest the best way to code a ComboBox in VBA that would potentially have a few hundred items in it?? It will be for users to select a year, starting say with 1930 and going as high as 2230.

I'm just not sure whether 'array' or 'additem' would be better or maybe I should be looking at some other alternative, like a text box with a spinner on it???

Hoping for ideas! Thanks!
 

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"
@Fluff perfect! I now have a valid date transferred to my worksheet and no errors! I am so grateful for all your help. If I could be indebted, I would be, but I have no Excel skills to offer! :)

With all of this troubleshooting, I'm not sure which post to mark as the solution. Ideas?
 
Upvote 0
You're welcome & thanks for the feedback.
I'd suggest marking post#32 as the solution.
 
Upvote 0
@Fluff oops, I may have spoken too soon. I just noticed that if I click the OKCommandButton with the three comboboxes empty, I get an error (run-time error 13: type mismatch) and the line of code "Dob = DateSerial(Me.YearComboBox, Month(DateValue(Me.MonthComboBox & "/01/2020")), Me.DayComboBox)" is highlighted in yellow. Can this be solved?
 
Upvote 0
I think it's important that users can update or change other controls on the userform without having to enter a date each time.
 
Upvote 0
How about
VBA Code:
   Dim Dob As Variant
   On Error Resume Next
   Dob = DateSerial(Me.ComboBox1, Month(DateValue(Me.ComboBox2 & "/01/2020")), Me.ComboBox3)
   On Error GoTo 0
   If IsDate(Dob) Then .Range("E9").Value = Dob.Value
 
Upvote 0
@Fluff that seems to work but I removed the .Value from the end of the last line of code. Is that OK?? I will continue to test the code and let you know how it turns out. Thank you again!
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,525
Members
449,088
Latest member
RandomExceller01

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