ComboBox Dropdown Open Automatically

JarekM

Board Regular
Joined
Nov 13, 2018
Messages
86
Hi, I have a problem regarding combobox. I would like it so when I select an item in list1 from combobox1, then it would automatically setfocus on combobox2 and the dropdown menu would open.

Here is a code that I tried, but doesn't work, when I hit enter, it only focuses on the combobox1:
VBA Code:
Private Sub ComboBox1_KeyPress(ByVal KeyCode As MSForms.ReturnInteger)
'Cancel = True
    If ComboBox1.ListIndex > -1 Then
        If KeyCode = 13 Then
            ComboBox2.SetFocus
            ComboBox2.DropDown
        End If
    End If
End Sub

Can someone help resolve this problem.
Thanks.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Hi, use KeyDown event.

VBA Code:
Private Sub ComboBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
     If ComboBox1.ListIndex > -1 Then
        If KeyCode = 13 Then
            ComboBox2.SetFocus
            ComboBox2.DropDown
       End If
    End If
End Sub
 
Upvote 0
Solution
Hi, use KeyDown event.

VBA Code:
Private Sub ComboBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
     If ComboBox1.ListIndex > -1 Then
        If KeyCode = 13 Then
            ComboBox2.SetFocus
            ComboBox2.DropDown
       End If
    End If
End Sub
Thank you, it works finally.
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,425
Members
448,961
Latest member
nzskater

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