Refer to all ComboBoxes on a form

craig.penny

Well-known Member
Joined
May 8, 2009
Messages
656
Hi all,

I have a userform with several ComboBoxes. When I click a Command Button, I'd like to clear them all out.

This is the code that goes with the Command Button:

Code:
Private Sub ClearCmndB_Click()
Dim CB As ComboBox
For Each CB In Me.ComboBoxes
      CB.Clear
Next CB
End Sub

As you can guess this doesn't work...

I've tried the variations that I can think of but I'd bet I'm missing the bigger picture on this.

Can someone give me an example of how to loop through all the ComboBoxes on the form?

Thanks in advance!!!
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Try
Code:
Dim oneControl as Object

For each oneControl in Me.Controls
    If TypeName(oneControl) = "ComboBox" then
        oneControl.Clear
    End If
Next oneControl
 
Upvote 0

Forum statistics

Threads
1,224,542
Messages
6,179,424
Members
452,914
Latest member
echoix

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