+ Reply to Thread
Results 1 to 8 of 8

Handling and storing values on global variables while running several macros

  1. #1
    Forum Contributor
    Join Date
    02-07-2012
    Location
    MIA
    MS-Off Ver
    Excel 2007, 2010
    Posts
    429

    Question Handling and storing values on global variables while running several macros

    Hello!

    I'm using a workbook that runs 15 macros which create 18 sheets of information based on 1 sheet of raw data. At the moment, the user has to input requested values that are used for the macro that is currently running, but many of these values are repeated and all of them could be entered at the beginning, upon launching the first macro, because they all refer to locations of the data fields from the first sheet of raw data. So I'm thinking that I should stop using local variables and store them for all the macros to use, and clear them only once all of them have run. The question is how do I define global variables and where should I place the code where the values for these are entered?

    Thanks in advance.
    Last edited by Pichingualas; 02-23-2012 at 10:56 AM.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,615

    Re: Handling and storing values on global variables while running several macros

    An easy way, though not the best: create new module and declare said variables as PUBLIC (for instance: Public Var1 As Long, Var2 As String, etc), use the WorkbookOpen event in the ThisWorkbook Module to initialize them.
    Ben Van Johnson

  3. #3
    Forum Contributor
    Join Date
    02-07-2012
    Location
    MIA
    MS-Off Ver
    Excel 2007, 2010
    Posts
    429

    Re: Handling and storing values on global variables while running several macros

    What way would be the best then?

  4. #4
    Forum Contributor
    Join Date
    02-07-2012
    Location
    MIA
    MS-Off Ver
    Excel 2007, 2010
    Posts
    429

    Re: Handling and storing values on global variables while running several macros

    Btw I don't want to use the workbook open event because this report is suposed to be executed only once a month.

  5. #5
    Forum Contributor
    Join Date
    02-07-2012
    Location
    MIA
    MS-Off Ver
    Excel 2007, 2010
    Posts
    429

    Re: Handling and storing values on global variables while running several macros

    So how do I make it for the user to input the value and let it fixed untill the last macro runs?

  6. #6
    Forum Contributor
    Join Date
    02-07-2012
    Location
    MIA
    MS-Off Ver
    Excel 2007, 2010
    Posts
    429

    Re: Handling and storing values on global variables while running several macros

    Also is there a way to clear them once the code stops so as not to waste memory space?

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Handling and storing values on global variables while running several macros

    Hi Pichingualas

    Something like this perhaps
    Please Login or Register  to view this content.
    In this instance MyString is available to all procedures in all modules until the code ends.

    If all procedures that require the variable are in the same module then perhaps this
    Please Login or Register  to view this content.
    In this instance MyString1 is available to all procedures in that module until the code ends.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  8. #8
    Forum Contributor
    Join Date
    02-07-2012
    Location
    MIA
    MS-Off Ver
    Excel 2007, 2010
    Posts
    429

    Re: Handling and storing values on global variables while running several macros

    Thanks I'll try this out.

+ 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