+ Reply to Thread
Results 1 to 3 of 3

Global Variable Resetting to Zero After 2 Successful Runs of a Function

  1. #1
    Registered User
    Join Date
    06-12-2012
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2010
    Posts
    54

    Global Variable Resetting to Zero After 2 Successful Runs of a Function

    Friends,

    I have a commandbutton that launches a userform that, on the first go around, initializes 5 textboxes to blanks. Then, the user's inputs are stored as global variables.

    The next time a user hits the command button the userform initializes to incremented values based on the global variables... and it works fine...

    BUT... the next time the command button is hit, the global variables have all mysteriously reset to zeros...

    Any idea why?

    Thanks in advance,

    -Mike

  2. #2
    Forum Contributor
    Join Date
    05-25-2012
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    194

    Re: Global Variable Resetting to Zero After 2 Successful Runs of a Function

    The only thing that would cause global variables to wipe is if your code crashes, or you re-open the workbook, etc. Rather than using global variables (which are really just supposed to be used for ease in passing between subroutines), explore using activeworkbook.customdocumentproperties - these are variables that you can define and are persistent even when the workbook closes and re-opens.

    You can set these variables up manually, or create them through vba using;

    Please Login or Register  to view this content.
    And then call them using;

    Please Login or Register  to view this content.

  3. #3
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Global Variable Resetting to Zero After 2 Successful Runs of a Function

    Or write the data to the worksheet

    we can't really comment without seeing your code.

+ 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