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?
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hi,

Which kind of combobox? An ActiveX combobox from toolbox? Then you can work with the following event of the combobox - "ComboBox1_KeyDown".
If you have many comboboxes you can work with classmodule.

If the combobox is in a userform then you can use the tabindex.

Case_Germany
 
Upvote 0
Hi again,

the following is for 4 comboboxes and belonged into the class module of the worksheet:

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 ComboBox1.Activate
End Sub
Case_Germany
 
Upvote 0
Hi...Sorry for bumping old topic...I don't understand why it didn't work...It didn't move to combobox2 when I press tab after I enter into comboBox1
anyone can shed some light into this?

Class Module
class.JPG


ComboBox1
ComboBox1.JPG
 
Last edited:
Upvote 0
Hi,

the code belonged into the class module of the worksheet "db" not into an extra class module.

Case_Germany
 
Upvote 0
Hi when I change comboBox1.Activate to commandButton1.Activate. The command button1 Disappears. Am I missing something?
If KeyCode = 9 Then If GetAsyncKeyState(16) Then ComboBox3.Activate Else ComboBox1.Activate
 
Upvote 0

Forum statistics

Threads
1,213,567
Messages
6,114,342
Members
448,570
Latest member
rik81h

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