skip set focus in specific textboxes when press enter

Alaa mg

Active Member
Joined
May 29, 2021
Messages
344
Office Version
  1. 2019
hi

I have multiple textboxes on user form for each five textboxes should ignore set focus for first two textboxes of them (textbox1,2,3,4,5) when run the userform should set focus in textbox 3 and move 4,5 and when move to next (textbox6,7,8,9,10) should set focus in textbox 8 and move 9,10 and so on for each five textboxes should ignore set focus the first two textboxes .
I hope this clear .
 
@Akuini thanks but how overcome problem cursor of mouse when put in textbox 1 should n't show the cursor . based on your code if I put cursor in textbox 1 should move the set focus to textbox3, and if i put the cursor in textbox 2 should move the set focus in textbox3
 
Upvote 0

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Here is part of sample on of UserForm in my workbook

VBA Code:
Option Explicit
Enum MouseButtons
    fmButtonLeft = 1                'The left button was pressed.
    fmButtonRight = 2              'The right button was pressed.
    fmButtonMiddle = 4           'The middle button was pressed.
End Enum

Private Sub Frame1_Click()
frmClick = True
End Sub

Private Sub TextBox1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)

Set rng = ActiveSheet.UsedRange

SelectOn = SelectCheck(rng, 2)

Select Case Button
    Case fmButtonLeft
        If SelectOn Then
            frmClick = True
            TextBox1.BackColor = &H80000005
            Me.TextBox1 = Split(ActiveCell.Address, "$")(1)
            ActiveCell.Font.ColorIndex = 1
            ActiveCell.Interior.ColorIndex = 2
            wsConfig.Range("C6") = TextBox1
            erow(1) = ActiveSheet.Range(Me.TextBox1 & 65536).End(xlUp).Row
            TextBox7.Value = ActiveCell.Row + 1
            TextBox8.Value = ArrayMaxVal(erow)
            frmClick = False
        End If
    Case fmButtonRight
        TextBox1.BackColor = &HE0E0E0
        TextBox1.Value = ""
    Case fmButtonMiddle

End Select
End Sub
 
Upvote 0
@Zot thanks . I try mod about part of code but it doesn't work at all
VBA Code:
Option Explicit
Enum MouseButtons
    fmButtonLeft = 1                'The left button was pressed.
    fmButtonRight = 2              'The right button was pressed.
    fmButtonMiddle = 4           'The middle button was pressed.
End Enum



Private Sub TextBox1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)

Select Case Button

    Case fmButtonLeft
            TextBox1.BackColor = &H80000005
        
        
    Case fmButtonRight
        TextBox1.BackColor = &HE0E0E0
        TextBox1.Value = ""
    Case fmButtonMiddle

End Select
End Sub

and this works but not completely
Code:
Private Sub TextBox1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
If Button = 1 Or Button = 2 Or Button = 4 Then
TextBox3.SetFocus
End If
End Sub
first when put cursor in textbox1 it move to textbox3 but when I try again . it keeps in textbox1
any idea,please?
 
Upvote 0
@Zot thanks . I try mod about part of code but it doesn't work at all
VBA Code:
Option Explicit
Enum MouseButtons
    fmButtonLeft = 1                'The left button was pressed.
    fmButtonRight = 2              'The right button was pressed.
    fmButtonMiddle = 4           'The middle button was pressed.
End Enum



Private Sub TextBox1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)

Select Case Button

    Case fmButtonLeft
            TextBox1.BackColor = &H80000005
       
       
    Case fmButtonRight
        TextBox1.BackColor = &HE0E0E0
        TextBox1.Value = ""
    Case fmButtonMiddle

End Select
End Sub

and this works but not completely
Code:
Private Sub TextBox1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
If Button = 1 Or Button = 2 Or Button = 4 Then
TextBox3.SetFocus
End If
End Sub
first when put cursor in textbox1 it move to textbox3 but when I try again . it keeps in textbox1
any idea,please?
Seems like it takes time ti reset trigger ? . I'm not sure what is the reason but it can be solved by applying same condition to MouseUp event

VBA Code:
Private Sub TextBox1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Button = 1 Then Me.TextBox3.SetFocus
End Sub

Private Sub TextBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Button = 1 Then Me.TextBox3.SetFocus
End Sub

Private Sub TextBox2_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Button = 1 Then Me.TextBox3.SetFocus
End Sub

Private Sub TextBox2_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Button = 1 Then Me.TextBox3.SetFocus
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,733
Messages
6,126,541
Members
449,316
Latest member
sravya

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top