Using "Tab" button to shift to next ComboBox?

Guanjin Peter

Active Member
Joined
May 21, 2008
Messages
429
is it possible to assign "tab" button, so that everyone I press tab, it'll shift from the first to another? when it reaches the last one, it'll go back to 1st?


and alt+tab to shift backwards?
 
Hi again,

if you liked to start the code of "CommandButton1", if the last "ComboBox" is selected, then that can be done for example in such a way:

Code:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer

Private Sub ComboBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    If KeyCode = 9 Then If GetAsyncKeyState(16) Then ComboBox4.Activate Else ComboBox2.Activate
End Sub

Private Sub ComboBox2_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    If KeyCode = 9 Then If GetAsyncKeyState(16) Then ComboBox1.Activate Else ComboBox3.Activate
End Sub

Private Sub ComboBox3_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    If KeyCode = 9 Then If GetAsyncKeyState(16) Then ComboBox2.Activate Else ComboBox4.Activate
End Sub

Private Sub ComboBox4_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    If KeyCode = 9 Then If GetAsyncKeyState(16) Then ComboBox3.Activate Else CommandButton1_Click: ComboBox1.Activate
End Sub

Private Sub CommandButton1_Click()
    MsgBox "Test"
End Sub
Case_Germany
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
sorry for ultra late reply. I was away. Thanks it works !


is it possible to add, on top of your codes, like alt+z and go back to combobox1?
 
Upvote 0
Hi again,

code in "ThisWorkbook":
Code:
Private Sub Workbook_Open()
    Application.OnKey "^{z}", "Module1.Test" ' adapt
End Sub

Private Sub Workbook_Deactivate()
    Application.OnKey "^{z}"
End Sub
Code in a module:
Code:
Sub Test()
    ThisWorkbook.Worksheets("Sheet1").ComboBox1.Activate ' adapt
End Sub
Look also into the VBA help for Application.OnKey

Case_Germany
 
Upvote 0

Forum statistics

Threads
1,213,538
Messages
6,114,220
Members
448,554
Latest member
Gleisner2

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