+ Reply to Thread
Results 1 to 5 of 5

IF statement comparing 2 ranges not giving correct result

  1. #1
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    IF statement comparing 2 ranges not giving correct result

    My code tests one range against another and changes the interior colour
    If the two ranges are equal the interior colour should change to orange. If the 2nd is less than the first then the interior colour should change to red.

    Please Login or Register  to view this content.

    I ran my code outputting the value of rng4, rng5 and the cell address of rng4 and rng5.

    27.63 27.63 $J$7 $J$8
    2.75 2.76 $K$7 $K$8
    12.46 12.46 $L$7 $L$8
    $M$7 $M$8
    $N$7 $N$8
    24.87 24.87 $O$7 $O$8
    15.17 15.17 $P$7 $P$8
    $Q$7 $Q$8
    $R$7 $R$8
    $S$7 $S$8
    $T$7 $T$8
    9.7 9.7 $U$7 $U$8
    $V$7 $V$8
    $W$7 $W$8
    $X$7 $X$8
    $Y$7 $Y$8
    $Z$7 $Z$8


    Based on these numbers J8, L8, O8, P8 and U8 should all be orange.
    But only J8 and L8 are orange.
    O8 and P8 are red.
    U8 is unchanged.

    I cannot work out why!
    Any ideas on where I might be going wrong?

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: IF statement comparing 2 ranges not giving correct result

    Hi,

    I'd guess you have very small floating point differences between the values. You might round them to say 3 decimal places
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Re: IF statement comparing 2 ranges not giving correct result

    All of the numbers should already be rounded to 2 decimal places but to make sure ...prior to going into an Access table all of the numbers are rounded to 2 decimal places.

    Is it possible that in the process of getting from Access to Excel the numbers are changing? As in changing from numbers rounded to 2 decimal place to numbers with more than 2 decimal places?
    The numbers are stored in Access as a number with a single field size.

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: IF statement comparing 2 ranges not giving correct result

    Did you try the rounding? If it works, that will answer your question.

  5. #5
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Re: IF statement comparing 2 ranges not giving correct result

    I did try rounding the numbers and it did solve the issue.

    I would like to know why the numbers are changing during the import process. I will start another thread to find an answer to that question.
    Thanks for your help. Much appreciated.

+ 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. If statement with standard deviation not giving correct value
    By excel12121 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-12-2016, 12:20 PM
  2. The formula is not giving the correct result
    By Patcheen in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 07-02-2016, 11:44 AM
  3. Replies: 11
    Last Post: 06-30-2016, 07:07 PM
  4. [SOLVED] Simple =Sum(B2:L2) result is not giving accurate result and =IMSUM(M2,O2) also.
    By SimonsGE in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-29-2013, 01:56 AM
  5. [SOLVED] "RIGHT" extracted value not returning correct result within IF statement
    By PlutoISaPlanet in forum Excel General
    Replies: 5
    Last Post: 11-05-2012, 04:02 PM
  6. IF THEN statement comparing Ranges of Numbers
    By Jupasto in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-31-2012, 12:07 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