excelvbasetfocus

TextBox and SetFocus VBA Excel


I have 3 couples of textboxes. I need to move the cursor on the first textbox of which the second textbox is not empty.

For example, I have the sixth textbox not empty and I need to move the cursor on the fifth textbox. I tried using SETFOCUS method but the cursor doesn’t move as I would like. I use AFTER UPDATE event. How it is possible to solve this problem?

Following similar code

Private Sub txtMain_AfterUpdate()
 
  Select Case True

        Case  txt2.Text <> ""
                txt1.SetFocus
        Case txt4.Text <> ""
                txt2.SetFocus
        Case txt6.Text <> ""
                txt5.SetFocus
        End Select
End sub

I tried using Change and Exit event


Solution

  • Hi all and thank you everyone. I have solved using KEYDOWN EVENT.

    Thank you