Question re: VBA ComboBox with many items

leopardhawk

Well-known Member
Joined
May 31, 2007
Messages
587
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!
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
58,246
Office Version
  1. 365
Platform
  1. Windows
Remove the .Value from Dob
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

leopardhawk

Well-known Member
Joined
May 31, 2007
Messages
587
Office Version
  1. 2016
Platform
  1. Windows
@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?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
58,246
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
I'd suggest marking post#32 as the solution.
 

leopardhawk

Well-known Member
Joined
May 31, 2007
Messages
587
Office Version
  1. 2016
Platform
  1. Windows
@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?
 

leopardhawk

Well-known Member
Joined
May 31, 2007
Messages
587
Office Version
  1. 2016
Platform
  1. Windows

ADVERTISEMENT

I think it's important that users can update or change other controls on the userform without having to enter a date each time.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
58,246
Office Version
  1. 365
Platform
  1. Windows
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
 

leopardhawk

Well-known Member
Joined
May 31, 2007
Messages
587
Office Version
  1. 2016
Platform
  1. Windows
@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!
 

Watch MrExcel Video

Forum statistics

Threads
1,132,912
Messages
5,655,911
Members
418,250
Latest member
Jebacmakro

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
Top