Combo and Text Boxes

Rocky0201

Active Member
Joined
Aug 20, 2009
Messages
278
Hi...

I have a Userform with approx. 50 combination of Textbox's, ComboBox's and ListBox's. When running code in the UserForm, is there a way that I can list the name of all of the Textbox's, ComboBox's and ListBox's?

In other words:

For i = 1 to The number of Box's

Do code

Next

I have an array setup, BoxArray, with box number of the Text, Combo and List box's. I'm looking to loop through the array and when I have a match to a box, execute some code.

Thanks.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
try some of the following ways of looping through controls on a userform:
Code:
Sub blah1()
UserForm3.Show False
For Each ctrl In UserForm3.Controls
    If TypeName(ctrl) = "ComboBox" Then MsgBox ctrl.Name    '(others are "ListBox" and "TextBox")
Next ctrl
End Sub

Sub blah2()
With UserForm3
    .Show False
    cbAry = Array(.ComboBox1, .ComboBox2, .ComboBox3, .ComboBox4, .ComboBox5)
    tbAry = Array(.TextBox1, .TextBox2, .TextBox3, .TextBox4, .TextBox5)
    lbAry = Array(.ListBox1, .ListBox2, .ListBox3, .ListBox4)
    For Each ctrl In cbAry
        Debug.Print ctrl.Name
    Next ctrl
End With
End Sub

Sub blah3()
With UserForm3
    .Show False
    cbAry = Array("ComboBox1", "ComboBox2", "ComboBox3", "ComboBox4", "ComboBox5")
    tbAry = Array("TextBox1", "TextBox2", "TextBox3", "TextBox4", "TextBox5")
    lbAry = Array("ListBox1", "ListBox2", "ListBox3", "ListBox4")
    For Each nm In cbAry
        Debug.Print .Controls(nm).Name'.Controls(nm).value
    Next nm
End With
End Sub

Sub blah4()
With UserForm3
    .Show False
    For i = 1 To 5
        Debug.Print .Controls("ComboBox" & i).Value
    Next i
End With
End Sub
 
Last edited:
Upvote 0
p45cal...

Is it possible to target just the page that I am on?

My UserForm1 has three pages. If I am on Page 1, can I just see the box's (Text, Combo, List) for the page that I am on? Is it possible to loop through just those box's and not all box's from the other two pages?

I stopped my app at a point where I can use Watch. I see we where I can use UserForm1.Control but I don't see how to drill down to the MultiPage that I is current using the same For loop that you have presented.

Thanks you very much for the help.
 
Upvote 0
the likes of:
For Each ctrl In UserForm3.MultiPage1.Pages(0).Controls
Pages on a 3 page multipage are numbered 0 to 2.

You can use the name of the page instead, default is like:
For Each ctrl In UserForm3.MultiPage1.Pages("Page1").Controls

current page is:
For Each ctrl In UserForm3.MultiPage1.Pages(UserForm3.MultiPage1.Value).Controls

 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,116
Messages
6,128,933
Members
449,480
Latest member
yesitisasport

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