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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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,224,584
Messages
6,179,691
Members
452,938
Latest member
babeneker

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