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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

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