skip set focus in specific textboxes when press enter

Alaa mg

Active Member
Joined
May 29, 2021
Messages
358
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 .
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
You can just set in userform property there.

Tab Sequence will control the sequence
Setting Tab Stop to False will make specific TextBox to be skipped.
 
Upvote 0
thanks but this way doesn't completely solve the problem . the problem is sometimes unintentionally I put the cursor of mouse in textbox is unwilling . then it shows .

I no know if there is way if it happens then should move the set focus to the firs textbox as is arranged based on order tab direcetly , when put the cursor in specific textbox should not set focus .
and move the cursor(set focus) to first textbox .
this way doesn't prevent set focus by mouse .
is that possible ?
 
Upvote 0
You can use the event such as
Private Sub TextBox1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)

Use the Button value to detect key press on any mouse button. Values are
Button = 1 (Left)
Button = 2 (Right)
Button = 4 (Middle)

and use the condition to set focus to specified field once click is detected.
 
Upvote 0
sorry I'm not professional at design the code . how code should be in MouseDown event ?
 
Upvote 0
I thought you already have userform with TextBox? If you select TextBox and browse the trigger event, one of them is MouseDown.

My understanding is that you are the one creating the UserForm, right?
 
Upvote 0
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
Try this:
VBA Code:
Private Sub TextBox1_Enter()
TextBox3.SetFocus
End Sub

Private Sub TextBox2_Enter()
TextBox3.SetFocus
End Sub

everytime you enter textbox1 or textbox2 it will automatically move the focus to textbox3.
 
Upvote 0
My understanding is that you are the one creating the UserForm, right?
yes but how use this ?
Button = 1 (Left)
Button = 2 (Right)
Button = 4 (Middle)
just put theses values in MouseDown event or waht?
 
Upvote 0
yes but how use this ?
Button = 1 (Left)
Button = 2 (Right)
Button = 4 (Middle)
just put theses values in MouseDown event or waht?
Once mouse button is clicked, it will produce Button value as stated automatically. So, use that value as trigger like
If Button = 1 then
...code here...
End if

Yes in that event
 
Upvote 0
Try this:
VBA Code:
Private Sub TextBox1_Enter()
TextBox3.SetFocus
End Sub

Private Sub TextBox2_Enter()
TextBox3.SetFocus
End Sub

everytime you enter textbox1 or textbox2 it will automatically move the focus to textbox3.
In Post #3 also want to prevent mouse to set focus.
 
Upvote 0

Forum statistics

Threads
1,216,813
Messages
6,132,845
Members
449,761
Latest member
AUSSW

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