+ Reply to Thread
Results 1 to 13 of 13

Macro Triggered By Combo Box

  1. #1
    Registered User
    Join Date
    02-16-2012
    Location
    Fag
    MS-Off Ver
    Excel 2003
    Posts
    9

    Macro Triggered By Combo Box

    Hello,

    I have a combo box that's embedded in a cell. It has three values: (blank), Yes and No. I would like to trigger a macro after a user selects an option from this combo box. I have the following code, but I can't seem to get it to work:

    Please Login or Register  to view this content.
    Any help would be great.

    Cheers

  2. #2
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Macro Triggered By Combo Box

    Assuming the name is correct, that should work. Is it even being triggered?
    Good luck.

  3. #3
    Registered User
    Join Date
    02-16-2012
    Location
    Fag
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Macro Triggered By Combo Box

    Hi Rory,

    It doesn't appear to be triggering. I've attached a sample of it
    Attached Files Attached Files

  4. #4
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Macro Triggered By Combo Box

    Ah - that is a data validation drop down - those do not have events and cannot have macros assigned to them. You will need a worksheet_change event instead. Right click the sheet tab, choose View Code and then paste this in, instead of what you have currently:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-16-2012
    Location
    Fag
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Macro Triggered By Combo Box

    Thanks Rory. Worked like a charm

  6. #6
    Registered User
    Join Date
    02-16-2012
    Location
    Fag
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Macro Triggered By Combo Box

    Hi again,

    I've just encountered a problem when I try to combine three of these as separate sub functions.


    Please Login or Register  to view this content.
    When I trigger any of the three combo boxes I receive the error: 'Compile error: Ambiguous name detected: Worksheet_Change.'

    Does that mean I have to somehow combine these under one sub function? Note, are you allowed to include wildcards in code? For instance in my second and third statements I use Yes# and No#. This is because I have multiple answers with Yes and no that I want the case trigger to apply to. Is this ok?

    Thanks again.

  7. #7
    Registered User
    Join Date
    02-16-2012
    Location
    Fag
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Macro Triggered By Combo Box

    Sorry to bump this, but is there an easy solution to the above?

  8. #8
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Macro Triggered By Combo Box

    You will have to combine them into one Change event. I'm not 100% clear on the wildcard issue - do you mean the cell contains 'Yes' somewhere in it?

  9. #9
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Macro Triggered By Combo Box

    You don't need any module.
    You should 'unmerge' F5 and G5 first.
    I'd prefer only 2 values in the validationlist: yes and no.
    the only code you need is:

    Please Login or Register  to view this content.



  10. #10
    Registered User
    Join Date
    02-16-2012
    Location
    Fag
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Macro Triggered By Combo Box

    Quote Originally Posted by OnErrorGoto0 View Post
    You will have to combine them into one Change event. I'm not 100% clear on the wildcard issue - do you mean the cell contains 'Yes' somewhere in it?
    Yes that's correct.

    SNB - my final spreadsheet has these combo boxes spread out over the full sheet. And in between there are other combo boxes with Yes/No answers. For user clarity I would prefer to keep these combo box answers in their existing format, rather than simplify them to 'yes/no'.

    Cheers.

  11. #11
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Macro Triggered By Combo Box

    Please Login or Register  to view this content.
    should do it. (untested)

  12. #12
    Registered User
    Join Date
    02-16-2012
    Location
    Fag
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Macro Triggered By Combo Box

    Excellent. Thanks OnErrorGoTo0. I removed the module1 from the second and third parts and it worked perfectly. Really appreciate your efforts on this. Although you don't know me, rest assured you made my day.

  13. #13
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Macro Triggered By Combo Box

    Glad to help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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