Help Please - Refering to TextBoxs with incremental names

BugEyedGiraffe

New Member
Joined
May 9, 2018
Messages
2
Hi there,

I have a UserForm with 50 Text Boxes that are named TextBox1, TextBox2 etc etc through TextBox50.

Is there a way I can refer to the boxes using a counter?
So I have a Integer Variable that increases by 1 based on some other code.
Can I have something like TextBox(Counter).Value or something like that?

Thank you in advance
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Yes that can be done but we need more specific details on what you want to do with these 50 textbox's

Are you going to enter values into all these textboxes and then want that data copied to you sheet?
 
Upvote 0
Here is a example of a script you can use to loop through 5 Userform Textbox's. Assuming they are all named "TextBox1" "TextBox2") etc.

The script will enter the Textbox's values into Row(2) of your Worksheet starting in column A

Code:
Private Sub CommandButton2_Click()
'Modified 5/9/18 8:30 PM EDT
    Dim i As Long
    For i = 1 To 5
        Cells(2, i).Value = Controls("Textbox" & i).Value
    Next
End Sub
 
Upvote 0
Thanks,

It was just how to format the reference to the text boxes so "Controls("TextBox" & i).Value" was exactly what I was looking for.

Cheers
 
Upvote 0
Glad I was able to help you.
Come back here to Mr. Excel next time you need additional assistance.
Thanks,

It was just how to format the reference to the text boxes so "Controls("TextBox" & i).Value" was exactly what I was looking for.

Cheers
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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