+ Reply to Thread
Results 1 to 6 of 6

VBA IF statement for cell values not equal not working

  1. #1
    Registered User
    Join Date
    05-03-2012
    Location
    OZ
    MS-Off Ver
    Excel 2016
    Posts
    18

    VBA IF statement for cell values not equal not working

    Hi

    I have two cell values (numbers returned using formulae) which return "TRUE" when equated in Excel i.e. A1 = B1 returns "TRUE".

    They also appear to be equal when I hover over the values in VBA, but the IF statement below does not work.

    Please Login or Register  to view this content.
    The problem is the first line of the IF statement. The two values appear to be equal but the IF statement returns True.

    If I subtract the two values in VBA, I get a number with many decimal places (not zero as I would expect) but the values themselves appear to be exactly the same even with decimal places in Excel.

    Thanks for any help!

  2. #2
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: VBA IF statement for cell values not equal not working

    Can you try rounding both values and then comparing??
    Cheers!
    Deep Dave

  3. #3
    Registered User
    Join Date
    05-03-2012
    Location
    OZ
    MS-Off Ver
    Excel 2016
    Posts
    18

    Re: VBA IF statement for cell values not equal not working

    How do I do that? (I would need to round to two decimal places and rounding would need to be done in VBA)

  4. #4
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: VBA IF statement for cell values not equal not working

    Something like this -

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-03-2012
    Location
    OZ
    MS-Off Ver
    Excel 2016
    Posts
    18

    Re: VBA IF statement for cell values not equal not working

    Seems to work! Thanks so much NeedForExcel!

  6. #6
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: VBA IF statement for cell values not equal not working

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ 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 - Check is the values are equal to the given numbers
    By geliedee in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 07-04-2016, 06:53 AM
  2. [SOLVED] Basic equal and not equal not working?
    By petermichael in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-18-2015, 09:25 AM
  3. [SOLVED] COUNTIFS function w/greater than or equal to, and less than or equal to time values
    By AliciaRenee in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 03-27-2014, 03:57 PM
  4. Replies: 2
    Last Post: 10-08-2013, 11:19 PM
  5. [SOLVED] Set a cell equal to another cell in an IF statement?
    By eface2face in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-19-2012, 10:16 AM
  6. [SOLVED] If statement won't recognize two values as equal
    By fiveironfrnzy08 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-20-2012, 04:59 PM
  7. Color cell with not equal values
    By vijay2482 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-12-2009, 05:22 AM

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