+ Reply to Thread
Results 1 to 6 of 6

Why doesn't the code reset?

  1. #1
    Registered User
    Join Date
    07-12-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    10

    Why doesn't the code reset?

    Hi there,

    I have a problem with my code and I have no idea why the code does not reset.

    The MainMenu of the code is as follows:

    Please Login or Register  to view this content.
    Basically the problem is this:
    When I declare RefNo = reff(manual input a number from 1 to 8), i.e. running the entire macro one at a time, I get my desired result. However when I use try to loop the entire macro (using the For Next loop) to work on 9 different types of data, the code returns the correct data for the first 2 and then doesn't run properly for the rest. I know the fault does not lie with the data because when I manually key in the number, ie declare RefNo = reff(manual input number from 1 to 8), I am able to get my result.

    Can someone explain why it is such? In short, my problem is that the code is able to run for one example at a time, but not all together.

    Many thanks in advance!

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983

    Re: Why doesn't the code reset?

    Withoutt examples of your workbooks & the full list of macro code it is almost inpossible to guess what the cause of the problem is
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Why doesn't the code reset?

    Do you get an error or is it just the outputted values are incorrect?

    If errorr then what and where.

    If incorrect output this would suggest you have variables that are retaining values from previous loop but should infact be reset.

    As most of your code has not been posted it's hard to say.
    Cheers
    Andy
    www.andypope.info

  4. #4
    Registered User
    Join Date
    07-12-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Why doesn't the code reset?

    Yes the output is not giving me the correct values. There's no errors. Andy, you mentioned that the variables are retaining values from previous loops. I did suspect this but I thought by using the Erase function to clear out all the arrays, that all of the variables would be cleared?

    The entire code is very long, that's why i'm hesitant to post it in its entirety.

  5. #5
    Registered User
    Join Date
    07-12-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Why doesn't the code reset?

    Or rather, in short, how do you reset codes?

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Why doesn't the code reset?

    Erase will reset the variables specified.

    Are those the only variables used in your other code?
    What about non array variables?

    As I said without seeing all the code, data and knowing what the result should be it very hard to guess.

    You will have to debug the code. First run the code without loops for a value where p gives an incorrect result when looping. For example if the results for p=2 are incorrect when looping run it once with p=2.

    Make a note of the calcuated values.

    Then run the code with loops. On the interation of P=2 check all the variables and try and identify where things start to differ.

+ 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