Loop through each combo box on userform

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,074
Office Version
  1. 2019
Platform
  1. Windows
I have 11 combo boxes (various names) on a userform. how can i create a vba code that will return each of the combo boxes back to index 0?

Thank you kindly for helping
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
VBA Code:
Dim oneBox as MsForms.Control

For each oneBox in Userform1.Controls
    If Typename(oneBox) = "ComboBox" Then
        oneBox.ListIndex = 0
    End If
Next oneBox
 
Upvote 0
Thank you Mikerickson. Its nice to see a familiar face still helping. You are greatly appreciated and an Oak :)
 
Upvote 0
On more request, how can exclude one of the combo boxes named cbName?
 
Upvote 0
Figure it out....

VBA Code:
Dim oneBox As MsForms.Control

For Each oneBox In frmData.Controls
    If TypeName(oneBox) = "ComboBox" Then
        If oneBox <> cbName Then
            oneBox.ListIndex = 0
        End If
    End If
Next oneBox
 
Upvote 0
Try
VBA Code:
Dim oneBox As MsForms.Control

For Each oneBox In frmData.Controls
    If TypeName(oneBox) = "ComboBox" And oneBox.Name <> "ComboBox1" Then
        If oneBox <> cbName Then
            oneBox.ListIndex = 0
        End If
    End If
Next oneBox
 
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,796
Members
449,095
Latest member
m_smith_solihull

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