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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

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
 
Upvote 0

XL Pro

Board Regular
Joined
Apr 17, 2002
Messages
249
Office Version
  1. 365
Platform
  1. Windows
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,187,178
Messages
5,962,048
Members
438,578
Latest member
MrJimC

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