Combobox Question

TonySondergeld

New Member
Joined
Jul 11, 2009
Messages
31
Hi all, I have a combobox (active x) on a sheet in excel 2007. What I want it to do is fill it with the Months (Auto, January to December) and also have it run (fill) when the workbook opens. The Auto in the combobox is used to run the reports at the current month and then you can select a month so to be able to lookup data when ever you want.
So I think to be able to run it a startup of the workbook it has to go into the module is this right as I have used this code before:
Sub Fill_CM_Months()
With Sheets("Dashboard")
.OLEObjects("CM_Months").ListFillRange = "Control!I3:I15"
End With
End Sub.

But it wont work in this instant.
Thanks for any help.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Try placing this in the ThisWorkbook module:

Code:
Private Sub Workbook_Open()
With Sheets("Dashboard")
.OLEObjects("CM_Months").ListFillRange = "Control!I3:I15"
End With
End Sub
 
Upvote 0
I Know it will work in either module or workbook however I must use the Additem and not the ListFillRange.
Know do I do this Sub Workbook_Open option
 
Upvote 0
Something like this perhaps?

Code:
Private Sub Workbook_Open()
Dim FirstRow As Integer
Dim LastRow As Integer
FirstRow = 3
LastRow = 15
For i = FirstRow To LastRow
Sheets("Dashboard").ComboBox1.AddItem Sheets("Control").Cells(i, 9)
Next i
End Sub
 
Upvote 0
I my looking for something more like this; however this has a problem
Private Sub Workbook_Open()
Dim FirstRow As Integer
Dim LastRow As Integer
Dim i As Integer
FirstRow = 3
LastRow = 15
For i = FirstRow To LastRow
Sheets("Dashboard").CB_MonthSelect.AddItem "Auto"
.AddItem "January"
.AddItem "Febuary"
.AddItem "March"
.AddItem "April"
.AddItem "May"
.AddItem "June"
.AddItem "July"
.AddItem "August"
.AddItem "September"
.AddItem "October"
.AddItem "November"
.AddItem "December"
Next i
End Sub
 
Upvote 0
To hard code each item, you can use this and it won't be tied to a range in the workbook any more:

Code:
Private Sub Workbook_Open()
With Sheets("Dashboard").CB_MonthSelect
.AddItem "January"
.AddItem "Febuary"
.AddItem "March"
.AddItem "April"
.AddItem "May"
.AddItem "June"
.AddItem "July"
.AddItem "August"
.AddItem "September"
.AddItem "October"
.AddItem "November"
.AddItem "December"
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,535
Messages
6,120,090
Members
448,944
Latest member
sharmarick

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