Combo box with a loop on a form

Fire_Chief

Well-known Member
Joined
Jun 21, 2003
Messages
664
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

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,358
Office Version
  1. 365
Platform
  1. Windows
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

Fire_Chief

Well-known Member
Joined
Jun 21, 2003
Messages
664
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

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,358
Office Version
  1. 365
Platform
  1. Windows
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,191,276
Messages
5,985,710
Members
439,975
Latest member
eelyn

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
Top