Determine if ActiveX ComboBox is deselected

kgartin

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

Some videos you may like

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.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
38,493
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
38,493
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
189
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
38,493
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
189
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
38,493
Office Version
365
Platform
Windows
You're welcome & thanks for the feedback
 

Watch MrExcel Video

Forum statistics

Threads
1,095,226
Messages
5,443,204
Members
405,219
Latest member
CraneS

This Week's Hot Topics

  • Copy entire row if CountA <>0 to another sheet
    [B]I want to copy entire row if CountA <>0 for column J7:AM7 (headers on J6:AM6) and so on till the last used cell is column D and paste the...
  • Select last used Row in Table
    I have created a Table in a Worksheet which is locked to prevent user errors and protect formula. Some of the cells require freetext entries which...
  • excel workbook: do not allow certain file name
    Hello all, Don't think this has ever been asked before, but how do I restrict file save [Before_Save Event] if the name of the file being saved...
  • fixing problem autofilter
    hello i need help about my code when i search by code in textbox it doesn't show anything this is my data [ATTACH type="full"...
  • “Weight”
    Hi, i’ve got a long sheet filled with weights such as kg,g,L & ml. i can build a formula to convert kg into g and liter into ml. How ever, my...
  • How to capitalize everything before a certain character?
    In column A, I have some text: Hello good day.mp3 Hello good day.flac etc. I'd like to capitalize everything before the period. I don't need the...
Top