+ Reply to Thread
Results 1 to 4 of 4

Variable values from one macro to another

  1. #1
    Registered User
    Join Date
    02-08-2005
    Location
    Kent, UK
    MS-Off Ver
    2010
    Posts
    69

    Question Variable values from one macro to another

    If I set a variable in one macro willl it still be set when I run another macro? What is happening is this:

    1. I receive one or more trackers from different agents

    2. These are placed in a central folder untouched

    3. I run my Excel macro. The starting macro is simply a a list of other macros it will run

    4. the list of macros are for each possible tracker I receive from our agents. If it finds one in the central folder it will do a bit of formatting then rename and copy the tracker to certain locations on the network and intranet. This all works fine so far.

    5. At this point I have a variable statement such as Agent1Tracker = Yes (baically to saythat yep the macro has found and updated that paritcular agent tracker)

    6. Then the theory is that the last sub macro will run Access. In Access there are macros assoicated to each agent tracker (to import their data into our db). What I'd like is that this only runs the Access macros that have a "Yes" variable and ignoring any trackers not found (just to be more efficient). So the statement is if, for example, Agent1Tracker = Yes then run Agent1Tracker Access macro

    This doesn't seem to work. Perhaps I'm not setitng the variable correctly but I've tried Agent1Tracker = Yes and it runs ALL Access macros. I've tried using Agent1Tracker = "Yes" (in speech marks) and it runs none of them.

    It's not a huge issue but if I only get one of our agent's trackers then running all the Access macros is a lot of wasted time.

    Basically then, if I set AgentxTracker to Yes in the first macros will it be remembered when it comes to the Access macro?

    The workaround it to just run all Access macros but I'd like to avoid this.

    Any ideas? I hope I've explained it well. If not please let me know?
    Last edited by koltregaskes; 08-25-2011 at 04:39 AM. Reason: No replies, adding question mark icon to see if this makes a difference

  2. #2
    Registered User
    Join Date
    02-08-2005
    Location
    Kent, UK
    MS-Off Ver
    2010
    Posts
    69

    Re: Variable values from one macro to another

    In answering my own question, I suppose what I could do if the variable value doesn't get remembered from macro to macro is to re-org all the macros:

    1. Set a check for each agent tracker in the starting macro

    2. If it finds a tracker then run the sub tracker

    2. Set the variable there when it returns to the starting macro

    3. Run the Access macros from the starting macro where the variables = Yes

    Is this what I need to do?

  3. #3
    Registered User
    Join Date
    02-08-2005
    Location
    Kent, UK
    MS-Off Ver
    2010
    Posts
    69

    Re: Variable values from one macro to another

    I've implemented my own suggestion of moving the variable statements all into the main macro but it still doesn't work. Any ideas? Is it simply because the variable is forgotten when you run another macro.

  4. #4
    Valued Forum Contributor
    Join Date
    08-29-2011
    Location
    Mississauga, CANADA
    MS-Off Ver
    Excel 2010
    Posts
    503

    Re: Variable values from one macro to another

    Hi,
    Why dont you just create a temporary Sheet where every macro will type the values you want to maintain then delete it with the last macro!

+ 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