Determine if ActiveX ComboBox is deselected

kgartin

Board Regular
Joined
May 6, 2010
Messages
184
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
30,122
Office Version
365
Platform
Windows
How about using a click event
Code:
Private Sub ComboBox2_Click()
instead
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
30,122
Office Version
365
Platform
Windows
Or depending on the settings, an exit event
Code:
Private Sub ComboBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
 

kgartin

Board Regular
Joined
May 6, 2010
Messages
184
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)
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
30,122
Office Version
365
Platform
Windows
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.
 

kgartin

Board Regular
Joined
May 6, 2010
Messages
184
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!!
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
30,122
Office Version
365
Platform
Windows
You're welcome & thanks for the feedback
 

Forum statistics

Threads
1,077,649
Messages
5,335,482
Members
399,018
Latest member
KathyMoUHC

Some videos you may like

This Week's Hot Topics

Top