+ Reply to Thread
Results 1 to 7 of 7

Is there a way to clear all variables after a loop?

  1. #1
    Forum Contributor
    Join Date
    03-04-2008
    Location
    Ohio
    MS-Off Ver
    Office 2010
    Posts
    208

    Question Is there a way to clear all variables after a loop?

    I'm using a block of code that was written by someone else to perform some calculations.
    This is a list of the variables created by the original authors of the program.

    Please Login or Register  to view this content.
    Because I ported this code into my spreadsheet, I suspect that there's some way that these get reset each time the code is run. Somehow, that 'reset' isn't working.
    Is there a way to clear all variables after each iteration?

    Thanks,
    -gshock
    Last edited by gshock; 08-12-2008 at 10:27 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    You need to post the code, remember to use Code Tags
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Those variables must have a value set within the code. This will overwrite any previous values. The variables will be cleared from memory when the workbook is closed.

  4. #4
    Forum Contributor
    Join Date
    03-04-2008
    Location
    Ohio
    MS-Off Ver
    Office 2010
    Posts
    208

    Exclamation

    Quote Originally Posted by royUK
    You need to post the code, remember to use Code Tags
    No worries, but don't say I didn't warn you. It's ugly. This was written by some engineers who don't necessarily understand the concept of writing efficient code.

    Please Login or Register  to view this content.
    If you can lend a hand, I would greatly appreciate it.

    Best,

    -gshock

  5. #5
    Forum Contributor
    Join Date
    03-04-2008
    Location
    Ohio
    MS-Off Ver
    Office 2010
    Posts
    208
    Quote Originally Posted by royUK
    Those variables must have a value set within the code. This will overwrite any previous values. The variables will be cleared from memory when the workbook is closed.
    Ah HA! That's exactly what the problem is! The workbook iterates through a number of stages. So the variables don't get cleared before the next stage is calculated.

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    To start tidying up. all constants & variables need to be at the top of the macro, before the actual code.

    This line makes no sense
    Please Login or Register  to view this content.
    It needn't be a loop because 2 to 2 would be 1.
    Last edited by royUK; 08-12-2008 at 11:21 AM.

  7. #7
    Forum Contributor
    Join Date
    03-04-2008
    Location
    Ohio
    MS-Off Ver
    Office 2010
    Posts
    208
    Quote Originally Posted by royUK
    To start tidying up. all constants & variables need to be at the top of the macro, before the actual code.

    This line makes no sense
    Please Login or Register  to view this content.
    It needn't be a loop because 2 to 2 would be 1.
    I'm just doing that to get it to run through once to see if I can find where it's causing the error. I have also tried running it through 4 loops using

    Please Login or Register  to view this content.
    If you notice the comment on that line, the code should loop through all the columns that have data based on the values in row 9. rylo helped me with the loop. Thanks for taking the time to look at this.

    Regards,
    Last edited by gshock; 08-12-2008 at 11:39 AM.

+ 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