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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
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
 
Upvote 0
Your code should work as is, just change

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

to

InputTable.Controls("txt" & i).TabIndex = i - 1
 
Upvote 0

Forum statistics

Threads
1,222,143
Messages
6,164,175
Members
451,880
Latest member
2da

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