Focus on Control on Excel User Form

How to focus on a specific control (TextBox1) on a user-form in MS-Excel
Barbara from Mumbai sent us this email:
I just created a user-form to calculate the perks and total salary package based on the entry of a basic salary. The form works fine but when I run the form the command box to calculate the perks and package is highlighted and I have to click in the textbox against the label name to start my entries. How can I avoid this situation so that the cursor appears inside the textbox against the label name automatically?

This problem has two solutions and you can use any one you like. You can watch the training video below (15.2 MB) before diving into the macro code.

The macro code for the various controls is given below:

Private Sub CommandButton1_Click()
TextBox3 = TextBox2.Value * (60 / 100) + TextBox2.Value * (15 / 100)
TextBox4 = Val(TextBox3) + Val(TextBox2)
End Sub

Private Sub CommandButton2_Click()
TextBox1 = “”
TextBox2 = “”
TextBox3 = “”
TextBox4 = “”
End Sub

Private Sub CommandButton3_Click()
End ‘You could also use Unload Me
End Sub

Private Sub UserForm_Activate()
End Sub

One thought on “Focus on Control on Excel User Form

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.