+ Reply to Thread
Results 1 to 4 of 4

Macro call dependent on value

  1. #1
    Forum Contributor
    Join Date
    01-21-2017
    Location
    England
    MS-Off Ver
    2007
    Posts
    409

    Macro call dependent on value

    Hi I would like to have a click button which runs different macros dependent on the value of a cell.

    so
    Sub Button3_Click()

    If worksheet "rota" cell M29= 1 then call test1
    M29= 2 then call test2
    M29= 3 then call test3
    M29= 4 then call test4

    Sub Test1()
    code I will write
    End Sub
    Sub Test2()
    code I will write
    End Sub

    for each of the tests.

    Thanks

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Macro call dependent on value

    Please Login or Register  to view this content.
    Be sure your called macros are in one of the numbered code modules for public access.
    Last edited by JLGWhiz; 08-31-2018 at 01:20 PM.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Forum Contributor
    Join Date
    01-21-2017
    Location
    England
    MS-Off Ver
    2007
    Posts
    409

    Re: Macro call dependent on value

    Thank you so much.

    Just as a sub question:

    I already have a test style vba

    Please Login or Register  to view this content.
    I want to make the code you gave me as part of test 2 on the above code.

    Can you have a test within a test. If it's not simple I'll start a separate thread.

    Cheers

  4. #4
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Macro call dependent on value

    You can, but you have to be careful not to create a perpetual loop of procedure calls by not having one of them eventually meet the condition that bypasses the call to the other marcro. In other words, they couldc conceivably sit there and call each other continually because neither of them contain code to change any of the conditions.

+ 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. Call the next macro if the first macro doesnt return results
    By geliedee in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-20-2016, 06:54 AM
  2. Outlook New_Mail Event Macro to Call Excel Macro
    By christopheralan88 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-29-2015, 06:28 PM
  3. Replies: 0
    Last Post: 03-26-2015, 12:07 AM
  4. Replies: 2
    Last Post: 08-13-2014, 06:39 PM
  5. Replies: 1
    Last Post: 08-13-2014, 05:46 PM
  6. Calling macro 10 times, add header list to macro call only once
    By capson in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-05-2013, 09:42 AM
  7. Replies: 4
    Last Post: 04-17-2013, 03:28 PM

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