Consulting

Results 1 to 11 of 11

Thread: ComboBox_Click event is firing for any change on any worksheet

  1. #1
    VBAX Regular 6StringJazzer's Avatar
    Joined
    Jun 2015
    Location
    Tysons Corner, VA, USA
    Posts
    10
    Location

    ComboBox_Click event is firing for any change on any worksheet

    Crossposted at Excel Forum and Stackoverflow but I'm not qualified to post links yet.

    I have isolated this problem to the workbook attached. This is from a complex application and I stripped it down to the bare minimum needed to reproduce the problem.


    There is one worksheet Labor with a combobox named ComboBoxRatesSelected.


    This combobox has a RowSource on sheet Parameters, and it has a LinkedCell on sheet Parameters.


    The code module for sheet Labor has an event handler for ComboBoxRatesSelected_Click.


    Whenever any change is made to any cell on any worksheet, the event handler is triggered twice. This happens even though the combobox is not clicked, and there is no code that changes the combobox. The only code in the entire workbook is the Click handler for the combobox. The event handler in this version simply puts up a message box.


    The only time I have ever seen unintended triggering of an event is if other code changes the value in the control, which will trigger a Click event. However, this stripped-down version rules that out.
    Attached Files Attached Files

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    I think I had to use MouseUp instead of Click or Change to get something working -- still don't know why though


    Option Explicit
    
    ' Update which rate sheet is displayed
    'Private Sub ComboBoxRatesSelected_Click() ' Change()
    '    MsgBox "ComboBoxClick occurred"
    'End Sub
    
    Private Sub ComboBoxRatesSelected_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
        MsgBox "ComboBoxRatesSelected_MouseUp occurred"
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Regular 6StringJazzer's Avatar
    Joined
    Jun 2015
    Location
    Tysons Corner, VA, USA
    Posts
    10
    Location
    Thanks, I had not thought of that. At this point I have developed another workaround but I'm still looking to understand how this event gets triggered without touching the combobox.

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I tried this:
    Copied RateList to Labor sheet and renamed it MyRates
    Set ListFillRange to MyRates
    Cut and pasted MyRates to Parameters which triggered Click macro
    Changes to Labor do not now trigger Click event

    Can't explain the behaviour though.
    Attached Files Attached Files
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    Mac reminded me of something ---

    Instead of using a formula for the named range RatesList, I used the 'real' address: =Parameters!$E$4:$E$12, and the event only seems to fire once

    So you can 'hard code' the named range or create it on the fly without using the formulas and it should work
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  6. #6
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    I have read where it is thought best to leave Named Ranges for worksheet formulas and code for all Ranges used in VBA.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  7. #7
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    Quote Originally Posted by SamT View Post
    I have read where it is thought best to leave Named Ranges for worksheet formulas and code for all Ranges used in VBA.
    Your homework assignment for tonight is to locate that reference

    I'd like to read a little more about that
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  8. #8
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Paul
    I recall SNB suggested that here
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  9. #9
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    Quote Originally Posted by mdmackillop View Post
    Hi Paul
    I recall SNB suggested that here
    Interesting

    But slightly different. The AtiveX's RowSource is still a Named Range. All I did was replace the dynamic named range RefersTo (which used the standard COUNTA(..) technique) with a static fixed range RefersTo

    I'm sure snb's point about avoiding RowSource is valid, but in THIS sitituation I think the formula was recalculating and that caused the _Change event to be re-triggered


    JUST A GUESS
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  10. #10
    VBAX Regular 6StringJazzer's Avatar
    Joined
    Jun 2015
    Location
    Tysons Corner, VA, USA
    Posts
    10
    Location
    Thank you for that! I almost never say this but it sounds like an Excel bug. Or possibly a file corruption.

  11. #11
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Homework. hehehe

    I gots more'n a hunnert programmin' sources I reads when I gets board. But, no, it wern't snb.

    'Ere, you look it up
    Attached Files Attached Files
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

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