Looping through textboxes

dave8

Active Member
Joined
Jul 8, 2007
Messages
275
I have a form with some textboxes, e.g., textbox1, textbox2, textbox3, etc. In VBA, I want to put values into these textboxes. How to reference the occurence of each textbox? For example, userform1.textbox1.value, userform1.textbox2.value, and so forth, but I want to do this in a loop because I have 15 or so textboxes to reference.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Code:
For i = 1 To 15
   Me.Controls("Textbox" & i).Text = ...
Next

FYI, if you use Google searching for your topic title, the 4th website already gives you similar code as above.

http://www.ozgrid.com/VBA/control-loop.htm
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,460
Messages
6,130,765
Members
449,589
Latest member
Hana2911

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