clear combo boxes in open workbook procedure

sulley333

Board Regular
Joined
Apr 29, 2010
Messages
71
I am looking to have all the combo boxes on my dashboard sheet cleared when the workbook is opened. Is this possible?

Thanks,
Lauren
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
First, open the Visual Basic Editor and place the following code in a regular module (Alt+F11 > Insert > Module)...

Code:
[font=Courier New][color=darkblue]Sub[/color] ClearComboBoxes()

    [color=darkblue]Dim[/color] Ctrl [color=darkblue]As[/color] OLEObject
    
    [color=darkblue]For[/color] [color=darkblue]Each[/color] Ctrl [color=darkblue]In[/color] Worksheets("Sheet1").OLEObjects
        [color=darkblue]If[/color] TypeName(Ctrl.Object) = "ComboBox" [color=darkblue]Then[/color]
            Ctrl.Object.Value = ""
        [color=darkblue]End[/color] [color=darkblue]If[/color]
    [color=darkblue]Next[/color] Ctrl
    
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
[/font]

Then, place the following code in the module for 'ThisWorkbook' (in the project explorer window on the left, right-click 'ThisWorkbook', and select 'View Code')...

Code:
[font=Courier New][color=darkblue]Private[/color] [color=darkblue]Sub[/color] Workbook_Open()
    [color=darkblue]Call[/color] ClearComboBoxes
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
[/font]

Then, exit the Visual Basic Editor (Alt+Q), and save your workbook. Now, whenever your workbook is opened, the ComboBoxes on the sheet specified within the code will be cleared.
 
Upvote 0

Forum statistics

Threads
1,224,618
Messages
6,179,917
Members
452,949
Latest member
beartooth91

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