Setting TabIndex using VBA

boileauj

New Member
Joined
Aug 12, 2009
Messages
12
I have a UserForm with 60 TextBoxes and other controls. I would like to write code that will loop through the TextBoxes and set the value of the TabIndex to be equal to that of the TextBox number so that they can be tabbed through in order. The code will look something like this:



Sub SetTabIndex ()

For i = 1 to 60

InputTable.Control("txt" & i).TabIndex = i - 1

Next i

End Sub



The TextBoxes are named "txt1"-"txt60" and the UserForm is "InputTable"

Is there any way to set the TabIndex using VBA?
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

pbt

Well-known Member
Joined
Oct 18, 2005
Messages
1,613
You could without code:

Open you Userform in VBA and right click it. Choose Tab Order.

From there you can move your Text Boxes up or down to whatever order you desire.

Harry
 

XL Pro

Board Regular
Joined
Apr 17, 2002
Messages
241
Your code should work as is, just change

InputTable.Control("txt" & i).TabIndex = i - 1

to

InputTable.Controls("txt" & i).TabIndex = i - 1
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,193
Messages
5,768,774
Members
425,492
Latest member
blueexcel123

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