Determine if ActiveX ComboBox is deselected

kgartin

Board Regular
Joined
May 6, 2010
Messages
201
I have a Private Sub that runs if an ActiveX ComboBox is CHANGED. The problem is, every time you type a letter in the open field (if a selection is not available) the code fires and slows down your typing.

Is there a way to determine if the text field of the combobox is deselected and if so, THEN fire the code? I don't really want to use the Private Sub - Worksheet/SelectionChange option since I'd have a similar effect every time a cell was selected.

Here's the code that runs:

Code:
Private Sub ComboBox2_Change()


    If Worksheets("JOB NAMES DATA").Range("K4") <> "x" Then
        Worksheets("PRESS RUN").Range("AA2") = Worksheets("JOB NAMES DATA").Range("K4")
        Worksheets("PRESS RUN").Range("Z2") = Worksheets("JOB NAMES DATA").Range("L4")
        Worksheets("PRESS RUN").Range("AC2") = Worksheets("JOB NAMES DATA").Range("M4")
    ElseIf Worksheets("JOB NAMES DATA").Range("K4") = "x" Then
        Worksheets("PRESS RUN").Range("Z2:AA2") = ""
        Worksheets("PRESS RUN").Range("AC2") = 1
    End If


End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
How about using a click event
Code:
Private Sub ComboBox2_Click()
instead
 
Upvote 0
Or depending on the settings, an exit event
Code:
Private Sub ComboBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
 
Upvote 0
Or depending on the settings, an exit event
Code:
Private Sub ComboBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)

Ooo that would work nicely but I don't see it as an option! I just copied your data and it took it but it does nothing. What am I missing? Do I need to set it up as a userform? (which it's currently NOT)
 
Upvote 0
You're quite right it doesn't exist, didn't realise that it was different for controls on a sheet.
Another option would be
Code:
Private Sub ComboBox1_LostFocus()
but you would need to click out of the combo to activate it.
 
Upvote 0
You're quite right it doesn't exist, didn't realise that it was different for controls on a sheet.
Another option would be
Code:
Private Sub ComboBox1_LostFocus()
but you would need to click out of the combo to activate it.

YES That's it!! I just figured it out and then read this! Anyway, you pointed me back to the options so thanks for the help!!
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,988
Members
448,538
Latest member
alex78

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