+ Reply to Thread
Results 1 to 4 of 4

Running a Macro off Data Validation Values

  1. #1
    Forum Contributor
    Join Date
    02-14-2011
    Location
    West Valley City, Utah
    MS-Off Ver
    Excel 2010
    Posts
    108

    Running a Macro off Data Validation Values

    Is there a function that will run a macro every time a bit of information is updated?

    For example, if I had a data validation list with Chevy, Toyota, and Mozda set in A1 and I have a macro called Macro1 that will hide row 11, Macro 2 that will hide row 12, and Macro3 that will hide row 13, is there any way to set up a function so that if A1 = "Chevy", run Macro1, if A1 = "Toyota", run Macro2, and if A1 = "Mozda", run Macro3?

    Part 2 if this question:
    If the above function is possible, can I use an If statement or some other sort of function so it is set up to unhide a row if the returned value is false? Aka, A1 = Chevy, so it runs Macro 1 to hide Row 11, and runs Macro 4 and 5 to unhide rows 12 and 13. Then if A1 is changed to = Toyota, it runs Macro 2 to hit Row 12, and runs Macro 4 and 6 to unhide rows 11 and 13, etc.

    Thanks for your time and response!

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Running a Macro off Data Validation Values

    Sky188,

    I'm assuming it's "Mazda" and not "Mozda". Also, I would discourage you from calling a multitude of other macros rather than just putting the code in the routine that will be calling them anyway.

    As to your question, you can use the worksheet_change event. The code would go in the appropriate sheet code module. Here's how it would look given your description:
    Please Login or Register  to view this content.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Forum Contributor
    Join Date
    02-14-2011
    Location
    West Valley City, Utah
    MS-Off Ver
    Excel 2010
    Posts
    108

    Re: Running a Macro off Data Validation Values

    Thanks for getting back to me on this tigeravatar, I really appreciate it!

    Is there any chance you could post an excel sheet with the above code working properly so I can mess around with it? I've never seen, used, or heard of the "event" capabilities of excel and the above code is completely unknown to me.

    Thanks a ton!

  4. #4
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Running a Macro off Data Validation Values

    Sky188,

    Attached is an example workbook based on the criteria described. When you select an item from the drop-down list in A1, the appropriate row is hidden.

    To view the code, press Alt+F11 to open the Visual Basic Editor (VBE) and then double-click on 'Sheet1' to view the Sheet1 code module.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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