Combo box with a loop on a form

Fire_Chief

Well-known Member
Joined
Jun 21, 2003
Messages
690
Office Version
  1. 365
Platform
  1. Windows
I have a form that has 64 combo boxes on it. I want to fine if any of them have the letters "TBA" in them.

I want the loop to stop at the first one it finds.

I have tried MANY for next loops and nothing works.

Writing out combobox1, combobox2, ect. in an If, else statement works but it's to long and I want to learn how to do it more efficiently.

Thank You

Marty
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
If the comboboxes are named ComboBox1, ComboBox2 etc try this.
Code:
For I = 1 To 64
    If Me.Controls("ComboBox" & I).Value = "TBA" Then
        MsgBox "ComboBox" & I & " is TBA."
        Exit For
    End If
Next I
 
Last edited:
Upvote 0
Thank You so much. It works fine.
If it's not to much can you explain why you use Me.Controls before ComboBox

Thank you again
 
Upvote 0
Me is a reference to the userform the controls are on, Controls is a property of the userform and it returns a collection of all the controls on the userform.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,621
Messages
6,120,568
Members
448,972
Latest member
Shantanu2024

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