Share via

UserForm TextBox Help

Anonymous
2020-01-06T21:33:55+00:00

I have the following code to check TextBox1 for a value.  If there is a value in TextBox1 that is greater than 0 then the value of TextBox2 is set to zero.  I have this portion of the VBA Code working fine.  What I am trying to accomplish is to skip the tab stop at TextBox2 if TextBox1 > 0.  However, the value of TextBox2 would need to be set at 0.  I have numerous rows of TextBoxes, in my UserForm, that I will be applying this to.

Private Sub TextBox1_Change()

    Dim TextBox1, TextBox2, TextBox3   'Declaring the TextBoxes involved in this particular scenario.

If TextBox1 > 0 Then

    TextBox2.Value = 0

ElseIf TextBox1.Value = 0 Then  'This is where the code throws the error message as indicated below.

    TextBox2.Value = 1

ElseIf TextBox1 > 0 Then

    TextBox3.SetFocus

    End If

End Sub

When I run this, I receive a Run-time error '424': Object Required message

Any help with this would be greatly appreciated.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2020-01-06T22:05:48+00:00

Since TextBox1 etc. are controls on your userform, you shouldn't declare them as variables.

And since you already handle TextBox1>0 in the first If TextBox1 > 0 Then, the ElseIf TextBox1 > 0 Then part will never be executed.

I wouldn't use the Change event, but the AfterUpdate event:

Private Sub TextBox1_AfterUpdate()

    If TextBox1 > 0 Then

        TextBox2 = 0

        TextBox3.SetFocus

    Else

        TextBox2 = 1

    End If

End Sub

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2020-01-07T13:45:02+00:00

    Thank you for your timely response HansV.  This worked like a charm.

    Was this answer helpful?

    0 comments No comments