Combobox Empty

Vampy99

New Member
Joined
Jul 13, 2011
Messages
42
Hi guys,

As previously mentioned, I'm a complete beginner with VB.

I have a form that pop's up when you click a button, please see the form below;

11mcowy.jpg


I can't get my info to populate the combobox's, please see my code below;

Private Sub UserForm1_Initialize()

UserForm1.Activate

comboday.Enabled
combomonth.Enabled
comboyear.Enabled



With comboday.Text

.AddItem "01"
.AddItem "02"
.AddItem "03"
.AddItem "04"
.AddItem "05"
.AddItem "06"
.AddItem "07"
.AddItem "08"
.AddItem "09"
.AddItem "10"
.AddItem "11"
.AddItem "12"
.AddItem "13"
.AddItem "14"
.AddItem "15"
.AddItem "16"
.AddItem "17"
.AddItem "18"
.AddItem "19"
.AddItem "20"
.AddItem "21"
.AddItem "22"
.AddItem "23"
.AddItem "24"
.AddItem "25"
.AddItem "26"
.AddItem "27"
.AddItem "28"
.AddItem "29"
.AddItem "30"
.AddItem "31"

End With

With combomonth

.AddItem "01"
.AddItem "02"
.AddItem "03"
.AddItem "04"
.AddItem "05"
.AddItem "06"
.AddItem "07"
.AddItem "08"
.AddItem "09"
.AddItem "10"
.AddItem "11"
.AddItem "12"

End With

With comboyear


.AddItem "2011"
.AddItem "2012"
.AddItem "2013"
.AddItem "2014"

End With

End Sub

The bits in bold are things I've added in to try to get them to work.

Can anyone help me?

Thanks,

Luke
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Luke Hi,

Comment out the following, not need to use the userform1.activate if you have added the code to the userform1.initialize

'UserForm1.Activate

'comboday.Enabled
'combomonth.Enabled
'comboyear.Enabled

with the with statement just refer to the combo no need to add the text

With comboday '.Text
 
Upvote 0
Also look to use a sheet to hold the data, so you can manage it easily rahter than have to come back to the code so look here

Excel Workbook
ABC
1DayMonthYear
2112011
3222012
4332013
5442014
655
766
877
988
1099
111010
121111
131212
1413
1514
1615
1716
1817
1918
2019
2120
2221
2322
2423
2524
2625
2726
2827
2928
3029
3130
3231
Sheet2

Then the code can refer to the sheet and cells.

<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> UserForm_Initialize()<br>Worksheets("Sheet2").Select<br>Range("A2").Select<br><SPAN style="color:#00007F">Do</SPAN> <SPAN style="color:#00007F">Until</SPAN> ActiveCell.Value = ""<br>Me.cboDay.AddItem ActiveCell.Value<br>ActiveCell.Offset(1, 0).Select<br><SPAN style="color:#00007F">Loop</SPAN><br>Range("b2").Select<br><SPAN style="color:#00007F">Do</SPAN> <SPAN style="color:#00007F">Until</SPAN> ActiveCell.Value = ""<br>Me.cboMonth.AddItem ActiveCell.Value<br>ActiveCell.Offset(1, 0).Select<br><SPAN style="color:#00007F">Loop</SPAN><br>Range("C2").Select<br><SPAN style="color:#00007F">Do</SPAN> <SPAN style="color:#00007F">Until</SPAN> ActiveCell.Value = ""<br>Me.cboYear.AddItem ActiveCell.Value<br>ActiveCell.Offset(1, 0).Select<br><SPAN style="color:#00007F">Loop</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0
Thanks for the response Trevor. I managed to get your method to work but preferred my own method, it turned out it was a problem with my Excel, I had to create the form before the button otherwise the combobox's would remain empty, weird I know.

Sorted now though

Thanks,

Luke
 
Upvote 0
Luke

The problem with your code was probably because you used UserForm1_Initialize.

You don't use the actual name of the form, UserForm1 will do.:)
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,777
Members
452,942
Latest member
VijayNewtoExcel

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