+ Reply to Thread
Results 1 to 7 of 7

Comparing values not providing expected results.

  1. #1
    Registered User
    Join Date
    10-25-2012
    Location
    Washington DC
    MS-Off Ver
    For MS 365
    Posts
    54

    Comparing values not providing expected results.

    Greetings.

    The simple sub below is passed a double variable for the purpose of setting a couple of other variables. The problem is that when I pass it a value of 500000 or 1000000 it is not providing the expected result. If AwardTotal is 1000000 I would expect AwardLevel to be 3 and ynSCplan to be set to true, but that's not what happens. AwardLevel gets set to 3, but ynSCplan is still false.

    Yes, the variable coming into the sub is also "double".

    Any idea as to why? Surely it's a "type" thing, no?

    Thanks!

    Please Login or Register  to view this content.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: Comparing values not providing expected results.

    The Case statement is a bit like an IF in that, once it finds a condition it likes, it exits the Select Case block.

    If you want both values set, you'd need to include an If statement in the level 3 Case to check for the higher value and set the flag.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Comparing values not providing expected results.

    Hi Max,

    You need a range for the third case argument (just like you've done for the first two cases) or else any value greater than 499,999.99 will always set AwardLevel to 3 as that's what it's been instructed to do.

    See how this goes:

    Please Login or Register  to view this content.
    HTH

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: Comparing values not providing expected results.

    @Trebor76: that's not going to set Level 3, just the flag.

    Regards, TMS

  5. #5
    Registered User
    Join Date
    10-25-2012
    Location
    Washington DC
    MS-Off Ver
    For MS 365
    Posts
    54

    Re: Comparing values not providing expected results.

    Thanks to both of you. Didn't realize the Case statement bailed out after finding the first match. Rookie mistake.

  6. #6
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Comparing values not providing expected results.

    @ TMS: Thanks for that!!
    @ Max_Taylor - try this:

    Please Login or Register  to view this content.
    Regards,

    Robert

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: Comparing values not providing expected results.

    You're welcome.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. autocomplete with vlookup providing multiple results
    By ejcnj in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-18-2013, 03:40 PM
  2. Replies: 1
    Last Post: 10-28-2010, 12:12 PM
  3. Chart providing different results
    By jamesryan in forum Excel General
    Replies: 2
    Last Post: 09-29-2010, 09:52 AM
  4. saving a xls as a csv - not getting expected results
    By Caconz in forum Excel General
    Replies: 4
    Last Post: 08-23-2010, 06:40 PM
  5. The ispmt function is providing unexpected results
    By Louis Zaffino in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-02-2006, 11:10 PM

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