+ Reply to Thread
Results 1 to 9 of 9

Array losing value after leaving "relevant module"???

  1. #1
    Registered User
    Join Date
    10-18-2011
    Location
    Where do we go now?
    MS-Off Ver
    Excel 2010
    Posts
    22

    Array losing value after leaving "relevant module"???

    Hey All,

    Couldn't find a post for this after searching Google, but my Array is losing it's values for the elements after it leaves the Module. See below both AV(1,1) and AV(1,2) have values while the program is in the EOY Module.

    ExcelCapture.jpg

    But as soon as it exits the "EOY" module and goes to the "Main" module the values become 0.

    ExcelCapture2.jpg

    Can anyone tell me why this is happening? Also, it's a big program so if you need a bit of the code let me know what part and I'll provide it. Thanks!!!

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Array losing value after leaving "relevant module"???

    Guess: The array is declared in the module "EOY" module and now you want to use it in a different module. Right?
    If "EOY" module is ended with sub then the value of the array will be lost.

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Array losing value after leaving "relevant module"???

    See Help for Understanding the Lifetime of Variables and Understanding Scope and Visibility
    Entia non sunt multiplicanda sine necessitate

  4. #4
    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: Array losing value after leaving "relevant module"???

    Hi Durlov

    Use a Public Variable...see this link
    http://books.google.com/books?id=0wC...ed=0CEEQ6AEwAg
    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.

  5. #5
    Registered User
    Join Date
    10-18-2011
    Location
    Where do we go now?
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Array losing value after leaving "relevant module"???

    Array is declared as a Public Variable in the Main module.

  6. #6
    Registered User
    Join Date
    10-18-2011
    Location
    Where do we go now?
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Array losing value after leaving "relevant module"???

    As Variant also - not sure if that matters

  7. #7
    Registered User
    Join Date
    10-18-2011
    Location
    Where do we go now?
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Array losing value after leaving "relevant module"???

    Also note that AV(1,3) maintains it's value for some reason.

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Array losing value after leaving "relevant module"???

    Can you post the code and/or attach a sample file?
    If posting code please use code tags, see here.

  9. #9
    Registered User
    Join Date
    10-18-2011
    Location
    Where do we go now?
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Array losing value after leaving "relevant module"???

    Okay my bad. First time I've written something this huge and not keeping track of the variables very well. I am using "Option Explicit", but still... Later on in the EOY module, because a variable is empty, the codes going into an if statement it's not supposed to.

    So sorry to waste your times, but still thanks for looking into it.

+ 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