Quick stupid question about "Sub ComboBox1_Click()"

TAPS_MikeDion

Well-known Member
Joined
Aug 14, 2009
Messages
622
Office Version
  1. 2011
Platform
  1. MacOS
Since I'm not that well versed in VBA, unlike most on this forum, I was hoping someone could answer a quick question regarding "Sub ComboBox1_Click()".

I thought this was a mouse click event, but as I seem to be finding out, it is also a key click event.

Is this correct?

I'm wondering, because I was trying to only use a mouse click to activate the drop-down in my ComboBox, but even the up/down keys are running the Sub ComboBox1_Click().

Thanks for any replies.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Yes, the ActiveX control works that way. As you navigate with keys, it is selecting and changing a value. This is what happens when you click a different value in the list.

There are coding ways to avoid that issue.
 
Last edited:
Upvote 0
Thank you for the info, Ken.

Do you happen to know what code is used to avoid this issue?
 
Upvote 0
Code:
'https://answers.microsoft.com/en-us/msoffice/forum/all/disable-userform-combobox-change-event-when-arrow/598b44a1-dcda-4a2c-8e12-2b84762f98ae
Dim ChangeNotOk As Boolean

Private Sub ComboBox1_Click()
If ChangeNotOk Then
    ChangeNotOk = False
   'User pressed arrow up or arrow down, do nothing
Else
    'your current change event code
    MsgBox "Click Event Fired Here"
End If
End Sub

Private Sub ComboBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    If KeyCode = 38 Or KeyCode = 40 Then
        ChangeNotOk = True
    End If
End Sub

Private Sub ComboBox1_Change()
    MsgBox "Change Event Fired"
End Sub
 
Upvote 0
I modified it as needed to get everything to work, and I GREATLY appreciate the help!

Sorry, one final thing...

In your code, I added "ElseIf KeyCode = 13 Then ChangeNotOk = False" in the "ComboBox1_KeyDown" sub, but I don't know how to get it to jump to and run the code in the "ComboBox1_Click" sub if the RETURN key is pressed.
 
Last edited:
Upvote 0
Disregard. It was an easy fix. I just had to use Call ComboBox1_Click after the ElseIf.

All set. Thanks again Ken!
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,183
Members
452,615
Latest member
bogeys2birdies

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