+ Reply to Thread
Results 1 to 5 of 5

Calling a macro from another macro while a condition is met

  1. #1
    Registered User
    Join Date
    10-15-2012
    Location
    severn, md
    MS-Off Ver
    Excel 2010
    Posts
    9

    Calling a macro from another macro while a condition is met

    I am trying to find a way to run only part of a macro from another macro while a variable condition is met. Let's call it "switch". I want to call macro1 from within another macro(macro2) while switch=1 and "turn macro1 off" when switch=0. The switch variable is just a dummy in macro1 whose only purpose is to switch macro1 on and off from macro2. I tried using a do while loop but I don't think that it checks the value constantly...any thoughts would be helpful

    Also my code is part of a project of macros that interact and is about 1500 lines long and I am trying to slim it out by not having to repeat code. That's why I am trying to call only portions of macros.

    Please Login or Register  to view this content.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,510

    Re: Calling a macro from another macro while a condition is met

    For that to work, you'd need to declare Switch as a global variable outside all the procedures. In that way, the variable is declared only once and all the procedures can "see" it.

    Other than that, you're approach should work.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,510

    Re: Calling a macro from another macro while a condition is met

    Note that when you say "run part of a macro", that cries out for that part of the code to be a re-usable subroutine or function to which you (could) pass parameters.


    Regards, TMS

  4. #4
    Registered User
    Join Date
    10-15-2012
    Location
    severn, md
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Calling a macro from another macro while a condition is met

    Thanks for the help! I got it to work. I just made additional subroutines and called them as needed.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,510

    Re: Calling a macro from another macro while a condition is met

    You're welcome.

+ 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