+ Reply to Thread
Results 1 to 5 of 5

unexpected result using if function

  1. #1
    Registered User
    Join Date
    10-17-2022
    Location
    toronto
    MS-Off Ver
    2021
    Posts
    40

    Question unexpected result using if function

    why excel shows result "YES" when =if(B2>1,"YES","NO") and B2 cell is "word"

    I expected the result to be error because Cell B2 was not a number, thx

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,732

    Re: unexpected result using if function

    Text values are considered to be "larger" than numeric values. This is because text comparisons are carried out by comparing the ASCII code of the characters ("A" has a code of 65, "B" is 66, and so on - lower case letters have codes which are 32 higher). The digits 0,1,2, etc. have codes which start at 48.

    Hope this helps.

    Pete

  3. #3
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: unexpected result using if function

    All text is treated as being greater than any number, hence you get "YES"

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,906

    Re: unexpected result using if function

    Try:

    =IF(ISTEXT(B2),"NO",IF(B2>1,"YES","NO"))
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  5. #5
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: unexpected result using if function

    You could use:

    =if(N(B2)>1,"YES","NO")

    since N will return 0 for text.
    Rory

+ 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. [SOLVED] unexpected result from VBA Typename function
    By Alan Beban in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-25-2018, 01:11 PM
  2. [SOLVED] MATCH function returns an unexpected result
    By Pepe Le Mokko in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-03-2013, 09:44 AM
  3. [SOLVED] MATCH function - unexpected #NA result
    By broncotundra in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-03-2013, 08:52 PM
  4. IF function gives unexpected result with different cell numbers
    By RICHMOND in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-31-2008, 06:58 AM
  5. Unexpected result
    By Biff in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-06-2005, 01:05 AM
  6. [SOLVED] Unexpected result
    By Biff in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-05-2005, 11:05 PM
  7. Unexpected result
    By Biff in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-02-2005, 10:05 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