+ Reply to Thread
Results 1 to 6 of 6

Loop through macros

  1. #1
    Registered User
    Join Date
    06-21-2016
    Location
    Minneapolis, Minnesota
    MS-Off Ver
    2010
    Posts
    16

    Loop through macros

    Hi All,

    I created a line graph and 4 buttons corresponding to a different line. When a button is clicked, it changes the color of a line to highlight it. Is it possible to assign all 4 macros to one button? I would like to click, run 1 macro, stop, and then with the next click run the next macro.

    Thanks in advance!

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Loop through macros

    Here is one method
    - keep score in (eg) cell A1 and make correct macro run based on value in A1

    Clicking button adds 1 to cell A1 value
    IF A1 = 1 run macro 1 and exit sub
    IF A1 = 2 run macro 2 and exit sub
    ..
    IF A1 = 4 run macro 4, make A1 = 0 and exit sub

    EDIT
    - Very similar to skywriter's method below which user a variable instead of a cell to keep score
    - I prefer skywriter's method
    Last edited by kev_; 02-09-2018 at 04:34 AM.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  3. #3
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Loop through macros

    In the thisworkbook module add this code.
    Please Login or Register  to view this content.
    In a new standard module add this code.
    Please Login or Register  to view this content.
    Point the button to the Sub CheckClickCount() macro.

    Where you see Macro1, Macro2 etc. put the actual names of your four macros, names only without the sub part.
    Last edited by skywriter; 02-08-2018 at 06:58 PM.
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

  4. #4
    Registered User
    Join Date
    06-21-2016
    Location
    Minneapolis, Minnesota
    MS-Off Ver
    2010
    Posts
    16

    Re: Loop through macros

    Quote Originally Posted by kev_ View Post
    Here is one method
    - keep score in (eg) cell A1 and make correct macro run based on value in A1

    Clicking button adds 1 to cell A1 value
    IF A1 = 1 run macro 1 and exit sub
    IF A1 = 2 run macro 2 and exit sub
    ..
    IF A1 = 4 run macro 4, make A1 = 0 and exit sub

    EDIT
    - Very similar to skywriter's method below which user a variable instead of a cell to keep score
    - I prefer skywriter's method
    This was great too. Thank you for taking the time

  5. #5
    Registered User
    Join Date
    06-21-2016
    Location
    Minneapolis, Minnesota
    MS-Off Ver
    2010
    Posts
    16

    Re: Loop through macros

    Quote Originally Posted by skywriter View Post
    In the thisworkbook module add this code.


    Point the button to the Sub CheckClickCount() macro.

    Where you see Macro1, Macro2 etc. put the actual names of your four macros, names only without the sub part.

    Many thanks! You sir, are a whiz!

  6. #6
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Loop through macros

    My pleasure, thanks for the feedback and rep. points.

+ 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. VBA, Do without loop, macros
    By BDD2015 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-27-2015, 04:21 AM
  2. Loop through multiple files and call macros (but unable to loop)
    By ryanpetersen in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-23-2014, 12:04 PM
  3. [SOLVED] Trying to loop this macros
    By wyldjokre69 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-02-2013, 12:29 AM
  4. loop recorded macros?
    By Nashvillbill in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-11-2013, 06:49 AM
  5. [SOLVED] how to fix do while loop for find macros
    By lottidotti in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-15-2012, 10:35 AM
  6. Call Macros before Next loop (loop creates new worksheets)
    By mantooth29 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-24-2012, 05:47 PM
  7. Do While Loop for Macros to run through various workbooks
    By kchm_2000 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-21-2011, 12:12 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