VBA & Macro Problems

Move Focus to the Next TextBox in a Microsoft Office VBA UserForm

Amos GikundaAmos Gikunda Nov 18, 2026 868 views

Question details

Move focus to the next TextBox after validating a VBA UserForm field.

Move Focus to the Next TextBox in a Microsoft Office VBA UserForm
Product
Microsoft Office VBA UserForms
Device & OS
not provided
Scenario
A user validates a TextBox in its Exit event and wants to continue to the next field.
Observed behavior
Focus remains in the first TextBox when its Exit event sets Cancel to True.
Before you start

Open the UserForm in the VBA editor and identify the TextBox Exit event that performs validation. Decide which validation conditions should keep the user in the current field.

Solution 1Recommended

Allow the TextBox Exit event to complete and check the Tab order

Use this when validation leaves focus in the current TextBox instead of moving to the next field.

Setting Cancel to True in a TextBox Exit event prevents the control from losing focus. Leave Cancel at its default value of False when validation succeeds; use True only when the user needs to correct the entry.

1
Open the Exit event

In the VBA editor, open the UserForm's code and select the current TextBox and its Exit event from the code window's drop-down lists.

2
Check the Cancel assignment

In the TextBox Exit procedure, remove an unconditional Cancel = True assignment. Set Cancel = True only when validation fails; when validation succeeds, leave it False or explicitly set Cancel = False.

3
Set the Tab order

In the UserForm designer, right-click the form and choose Tab Order. Place the next TextBox immediately after the current one, and check that the next TextBox is enabled, visible, and has TabStop set to True.

4
Test the form

Run the UserForm, enter a valid value, and press Tab. Focus should move to the next TextBox without a SetFocus call. Test an invalid value to confirm that focus stays in the current field.

Allow the TextBox Exit event to complete and check the Tab order
Preserve validation: Do not force Cancel to False for invalid input if the form must keep focus in the field until the value is corrected.
Free Microsoft Office alternative

Use WPS Office for Everyday Office Documents

WPS Office is a free, lightweight alternative with a familiar interface and support for common Microsoft Office formats, making it easier to move everyday documents between suites. It does not fix Microsoft Office VBA UserForm events, and VBA compatibility may vary.

A familiar interface for working with documents, spreadsheets, and presentationsCompatibility with common Microsoft Office formats, including DOCX, XLSX, and PPTXA free, lightweight option for everyday Office workAn alternative for editing spreadsheet content while keeping VBA UserForm troubleshooting in Microsoft Office
microsoft office alternative - wps office

Frequently Asked Questions

Why does focus stay in my VBA TextBox after validation?

Check the TextBox Exit procedure in the VBA editor. If it sets Cancel = True, the control cannot lose focus. Use that setting only when validation fails.

Do I need SetFocus to move to the next TextBox?

Usually not. If the Exit event is not canceled and the next TextBox is enabled, visible, and next in the Tab order, pressing Tab should move focus automatically.

Where can I change the UserForm Tab order?

In the VBA UserForm designer, right-click the form and select Tab Order. Move the controls into the desired sequence.

Should I remove Cancel = True from all validation code?

No. Keep Cancel = True for invalid input when the user must correct the current field. Leave Cancel False when the input passes validation.