Fix VBA UserForm TextBox Error 424 and Move Focus
Question details
The user needs to update one UserForm TextBox based on another and move focus without triggering error 424.

- Product
- Microsoft Office VBA UserForm
- Device & OS
- not provided
- Scenario
- A UserForm should set TextBox2 to zero and move focus to TextBox3 when TextBox1 contains a value greater than zero.
- Observed behavior
- The VBA code produces Run-time error 424 instead of completing the update and focus change.
Open the UserForm in the Visual Basic Editor and check that the controls are named TextBox1, TextBox2, and TextBox3. Make sure TextBox3 is visible and enabled so it can receive focus.
Use the TextBox1 AfterUpdate event and reference the controls directly
Use the UserForm's existing TextBox controls instead of declaring variables with the same names, then update TextBox2 after the user changes TextBox1.
The AfterUpdate event runs after a changed value is committed. Referencing the controls through Me helps distinguish them from local variables.
In the Office application's Developer tab, select Visual Basic. In the Project Explorer, find the UserForm and open its code window.
Remove any declarations that create local variables named TextBox1, TextBox2, or TextBox3 in the affected procedure. These names should refer to the controls on the UserForm.
In the UserForm code window, add or replace the TextBox1_AfterUpdate procedure with: Private Sub TextBox1_AfterUpdate() If Not IsNumeric(Me.TextBox1.Value) Then Exit Sub If CDbl(Me.TextBox1.Value) > 0 Then Me.TextBox2.Value = 0 Me.TextBox3.SetFocus Else Me.TextBox2.Value = 1 End If End Sub
Run the UserForm and enter a positive number in TextBox1, then leave the field. Confirm that TextBox2 changes to 0 and focus moves to TextBox3. Try zero or a negative number to confirm that TextBox2 changes to 1.

Work with Office spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with Office documents and spreadsheets. It can help you move everyday files between office suites, but it does not fix errors in Microsoft Office VBA code.

Frequently Asked Questions
Why does my UserForm code show Run-time error 424?
Error 424 means an object is required. Check the highlighted line in the VBA editor and remove local variables that shadow the UserForm controls, then refer to the controls with names such as Me.TextBox2.
When does TextBox1_AfterUpdate run?
It runs after a changed TextBox1 value is committed, typically when the user leaves the field. Put the procedure in the UserForm's code window, not in a standard module.
Why won't TextBox3 receive focus?
Check TextBox3's Visible and Enabled properties in the UserForm designer. The control must be available to receive focus when Me.TextBox3.SetFocus runs.
What happens if TextBox1 contains text instead of a number?
The IsNumeric check in the example exits the procedure without updating TextBox2. You can add a message or other validation in that branch if the user should be prompted to enter a number.




