TextBox number as a variable

plix

Board Regular
Joined
Oct 10, 2006
Messages
187
I have 5 text boxes in a form, numbered 2 to 6.
I have a command button which is supposed to trigger the following action: for each of these text boxes, look up the corresponding value in a sheet and delete it.

I want to do a "For...Next..." type loop and I am trying to use a variable n to refer to the text box number.

I tried TextBox(n).value but apparently the syntax is not valid.

Can anyone help?
Thanks,

Plix
 

Some videos you may like

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

xld

Banned
Joined
Feb 8, 2003
Messages
5,378
Code:
For i = 2 To 6

'use Me.Controls("TextBox" & i).Text to get the value
Next i
 

Watch MrExcel Video

Forum statistics

Threads
1,122,822
Messages
5,598,304
Members
414,224
Latest member
Crazy_FC

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