+ Reply to Thread
Results 1 to 11 of 11

ComboBox Change Event Issue

  1. #1
    Registered User
    Join Date
    02-25-2014
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    46

    ComboBox Change Event Issue

    I have an ActiveX ComboBox populated by a named range that I would like to have run a macro whenever the user changes the value. This box works fine, however, I have another separate macro that is used to update the named range that is linked to that ComboBox. This leads to the _Change() event being triggered (as well as an error being thrown) whenever I try to update the named range. The macro for the ComboBox is simply:

    Please Login or Register  to view this content.
    Is there a way to have that macro run only when the user selects a new drop-down item and not when the named range is updated by a separate macro?

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: ComboBox Change Event Issue

    You could check if the user has actually made a selection in the combobox.
    Please Login or Register  to view this content.
    Or you could populate the ComboBox differently, eg by using List when the sheet is activated.
    If posting code please use code tags, see here.

  3. #3
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: ComboBox Change Event Issue

    you need to stop events when running your second macro.

    run your second macro

    Start events.

    Please Login or Register  to view this content.

    Also useful are:

    Please Login or Register  to view this content.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  4. #4
    Registered User
    Join Date
    02-25-2014
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    46

    Re: ComboBox Change Event Issue

    Norie,

    Where would I place that bit of code? I tried doing it like so:

    Please Login or Register  to view this content.
    ...but I still received the same error as I was before.

  5. #5
    Registered User
    Join Date
    02-25-2014
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    46

    Re: ComboBox Change Event Issue

    mehmetcik,

    I added the 'Application.EnableEvents = False' to the macro that I have to update the named range, but the _Change() event still seems to be triggered.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: ComboBox Change Event Issue

    What error are you getting?

  7. #7
    Registered User
    Join Date
    02-25-2014
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    46

    Re: ComboBox Change Event Issue

    It's a run-time error that comes as a result of the wrong macro being called due to _Change() event being triggered by the named range being updated. Basically, I am looking for a way to run the ComboBox macro only when the selected value is changed and not when the named range that populates its list changes. I have tried both disabling events on the macro that updates the named range as well as your suggestion and neither seem to work.

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: ComboBox Change Event Issue

    Disabling events using Application.EnableEvents does not affect controls.

    You need to either populate the listbox in a different way so that it's not directy linked to the named range or stop the code in the change event being triggered using a global variable.

    For the latter add this in a standard module.

    Please Login or Register  to view this content.
    Now in the change event test boolenabled.
    Please Login or Register  to view this content.
    Now at the start of the sub that changes the named range add this,
    Please Login or Register  to view this content.
    and add this at the end of the code in that sub.
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    02-25-2014
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    46

    Re: ComboBox Change Event Issue

    I just tried this out and it still seems to call _Change() macro. I am not completely familiar with structuring VBA modules and such, but I have the following:

    A worksheet module:
    Please Login or Register  to view this content.
    A module with only:
    Please Login or Register  to view this content.
    A module to set named range:
    Please Login or Register  to view this content.
    And a module that should run when the ComboBox selection changes.

    I have a feeling these are not set up properly, but I'm unsure of which changes to make.

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: ComboBox Change Event Issue

    Oops, boolDisabled needs to be declared as Public.
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    02-25-2014
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    46

    Re: ComboBox Change Event Issue

    I think I got it working finally. Thanks for all the help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] UserForm ComboBox Change Event Question
    By tja1964 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-10-2012, 07:21 PM
  2. Change event for comboBox
    By cmpcwil2 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-04-2006, 10:01 AM
  3. [SOLVED] Combobox change event issue
    By Excelerate-nl in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-04-2006, 08:10 AM
  4. Combobox change event only by UI
    By Excelerate-nl in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-02-2006, 11:10 AM
  5. MsgBox in Enter event causes combobox not to run Change event
    By Richard in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-06-2006, 10:55 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1