+ Reply to Thread
Results 1 to 4 of 4

Modifying Global Variables in Procedures

  1. #1
    Registered User
    Join Date
    04-22-2012
    Location
    Syracuse, NY, USA
    MS-Off Ver
    Office 365
    Posts
    61

    Modifying Global Variables in Procedures

    This is probably a basic of basics question:

    If I declare a variable at module-level as Public and then assign it a value in a UserForm_Initialize() subroutine. Will the value of that variable be available to any other procedure within that same UserForm or do I have to reassign the value each and every time?
    Reality is stranger than fiction.

  2. #2
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Modifying Global Variables in Procedures

    It will be available as long as the same procedure is running. Once the procedure is stopped and a new one is started it will reset. With a user form this will keep the value as long as the form has not unloaded. So you can run many different proceedures in the user form and it will always keep its original value from the Initialize routine.
    Last edited by JapanDave; 06-21-2013 at 08:37 PM.
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

  3. #3
    Registered User
    Join Date
    04-22-2012
    Location
    Syracuse, NY, USA
    MS-Off Ver
    Office 365
    Posts
    61

    Re: Modifying Global Variables in Procedures

    If I have a procedure within that UserForm modify the value of the variable will it remain modified after the procedure completes or will it revert back to it original value?

  4. #4
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Modifying Global Variables in Procedures

    It will remain the modified until you change it again. It will not revert back unless you change it back.

+ 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