+ Reply to Thread
Results 1 to 17 of 17

If Statement Erroring at Runtime

  1. #1
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    If Statement Erroring at Runtime

    Hi all,

    I am attempting to create what my user is calling an escalator. If the escalator option is selected on my user form, the user can tweak the weight percentages. The sum of these weights must = 1 (see picture[I know you all love pictures]). I have the following code that is supposed to sum the weights and let the user know if they are not equaling 1. The problem I am having, and I must say that it is not all the time, is; if the user's weights = 1, the error message comes up saying that the escalator should = 1, the current sum of values =1. ???? If the sum =1 then everything SHOULD be okay. The code:
    Please Login or Register  to view this content.
    EscSum, when stepping through it equals 1 but
    Please Login or Register  to view this content.
    does not compute right for some reason. Hopefully someone can see in this little section of code how this is not working out right for me. The file can be located here. Like I have previously stated, this problem does not occur all of the time which confuses me even more.
    Last edited by Mordred; 11-04-2011 at 01:10 PM.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: If Statement Erroring at Runtime

    Hello Mordred,

    I don't see any variable declarations. What variable type is EscSum?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: If Statement Erroring at Runtime

    Sorry Leith, I didn't want to bombard the forum with all the code. EscSum is a double.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: If Statement Erroring at Runtime

    Hello Mordred,

    In that case, it is probably a rounding problem. Select a variable type that matches the maximum number of decimal places you need. Converting a Double down to another smaller number type like Single, or Long will still be rounded. Another method would be Fix the value to a set number of digits.

  5. #5
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: If Statement Erroring at Runtime

    Quote Originally Posted by Leith Ross View Post
    Another method would be Fix the value to a set number of digits.
    Hi Leith, I'm not sure about how to do that (or what you mean).

  6. #6
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: If Statement Erroring at Runtime

    Another possibility - I don't see anywhere in your code where you're initialising the value of EscSum, shouldn't you have an EscSum=0 in there before you go into your EscCntr loop?

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: If Statement Erroring at Runtime

    Hello Morderd,

    Here is an example of fixing the decimal places.
    Please Login or Register  to view this content.

  8. #8
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: If Statement Erroring at Runtime

    Hi Andrew, I have specifically declared EscSum to = 0 but it did not seem to make a difference. By default though, it is 0.

  9. #9
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: If Statement Erroring at Runtime

    Thanks Leith, I'm sure your advice will work once I figure out how to work it into what I already have. I'll let you know how it goes.

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: If Statement Erroring at Runtime

    Hello Mordred,

    If you get stuck, you know where to find to me.

  11. #11
    Forum Moderator vlady's Avatar
    Join Date
    09-22-2011
    Location
    Philippines - OLSHCO -Guimba-Nueva Ecija
    MS-Off Ver
    2021
    Posts
    4,361

    Re: If Statement Erroring at Runtime

    hello
    why is it not inside for next loop

    If EscSum<>
    endif
    I think people forget the word "THANK YOU!!!!" Do you still know it???

    There is a little star ( ADD REPUTATION ) below those person who helped you. Click it to say your "PRIVATE APPRECIATION TO THEIR EFFORT ON THEIR CONTRIBUTIONS "

    Regards,
    Vladimir

  12. #12
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: If Statement Erroring at Runtime

    Hi vlady,
    Please Login or Register  to view this content.
    is not in the loop because it checks the total sum of Esc values. That sum can't be determined until after the loop.

  13. #13
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: If Statement Erroring at Runtime

    @Leith, I can't figure out how to apply your fix to my problem. I have tried
    Please Login or Register  to view this content.
    but that seems to round the EscSum2 value down to 0 after each iteration of the for loop.

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

    Re: If Statement Erroring at Runtime

    FIX will return the integer portion of a number. So if the value is less than 1 you will get zero.

    maybe try
    Please Login or Register  to view this content.
    Or use the FIX here
    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  15. #15
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: If Statement Erroring at Runtime

    Thanks Andy, so far
    Please Login or Register  to view this content.
    is working properly. Thanks for your assistance!

  16. #16
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: If Statement Erroring at Runtime

    BTW

    Please Login or Register  to view this content.
    Last edited by snb; 11-04-2011 at 12:45 PM.



  17. #17
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: If Statement Erroring at Runtime

    Thanks everyone, I'm going with snb's solution, it works perfectly for my purposes.

+ 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