I have a UserForm which asks for a date with three separate ComboBox (month, day, year).
I have initialized them as follows:
What I am trying to do is pre-set them with the current date. I have attempted it with the commented out code at the bottom which gives an error "Type Mismatch"Public Sub UserForm_Initialize() ' Add months to the ComboBox With Month For x = 1 To 12 .AddItem (x) Next x End With ' Add days to the combo box With Day For y = 1 To 31 .AddItem (y) Next y End With ' Add Years to the combo box With Year For y = 2010 To 2015 .AddItem (y) Next y End With Shift.AddItem "Day" ' Add day shift Shift.AddItem "Night" ' Add night shift 'Month.Value = Month(Date) 'Day.Value = Day(Date) 'Year.Value = Year(Date) End Sub
Any ideas on how I can successfully pre-set them?
Thanks!
Also posted at: http://www.mrexcel.com/forum/showthr...15#post2382015
Last edited by nbuk; 07-20-2010 at 11:22 AM.
I have also tried using ListIndex but I still get the same error.
Month.ListIndex = Month(Date) Day.ListIndex = Day(Date) Year.ListIndex = Year(Date)
Why not using a combobox with all the dates of this year ?
Combobox.List = Filter([transpose(Text(today()-(today()-date(year(today()),1,0))+row(1:365),"dd-mm-yyyy"))], "-")
Putting all the dates of the year into one combobox would make it very large, no?
I am not familiar with how this code works. Could you please explain exactly what it does?
Thanks
Edit:
I tried the code and it works fine with displaying the dates, but today's date is not pre-selected, which is what I need. Is there any way to add on to that?
Last edited by nbuk; 07-20-2010 at 11:32 AM.
There's an example of using Comboboxes for dates here
http://excel-it.com/free_addins.htm
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel Tips & Solutions, free examples and tutorials why not check out my downloads
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
snb,you've already been asked when posting complex code,in my opinion overly complex, to add explanations.
You never seem to bother following up on any requests from members
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel Tips & Solutions, free examples and tutorials why not check out my downloads
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
Sub snb() With Combobox1 .List = Filter([transpose(Text(today()-(today()-date(year(today()),1,0))+row(1:365),"dd-mm-yyyy"))], "-") .value=date End With End Sub
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks