+ Reply to Thread
Results 1 to 18 of 18

Fail to compare text in two cells with IF

  1. #1
    Registered User
    Join Date
    04-07-2019
    Location
    Hanoi, Vietnam
    MS-Off Ver
    16001.11425.20056.0
    Posts
    13

    Fail to compare text in two cells with IF

    Hello.
    I'm trying to do a little work on excel but it has the problem. I have a table like this:

    excel last season.png

    I want to check the season number in column E with the season number in column F so I write a formula like this:

    =IF(F2=("Season "&E2);"yes";"no")

    and put it into column G said cell G2. But it says "no" for every pair even if the number is the same. I think it was because the format of the two things weren't the same so I changed to another formula which I know a little information from Google. It was:

    =IF(TEXT(F2;"0")=TEXT("Season "&E2;"0");"yes";"no")

    But this time it said "no" for everything also even the number was the same.
    Any one tell me know what's wrong with my formulas please. I think I didn't know something that I should have known.
    Thanks.
    Last edited by AliGW; 08-13-2019 at 05:16 AM. Reason: Irrelevant section of title removed.

  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,724

    Re: [PROBLEM] Fail to compare text in two cells with IF

    Perhaps you have a space or a non-breaking space character at the end of "Season 6".

    It would help if you attached a sample Excel workbook, then we can check for ourselves.

    To do this, click on Go Advanced (below the Edit Window) while you are composing a reply, then scroll down to and click on Manage Attachments and the Upload window will open. Click on Browse and navigate to (and double-click) the file icon that you want to attach, then click on Upload and then on Close this Window to return to the Edit window. When you have finished composing your post, click on Submit Post.

    Don't try to use the Paperclip icon, as it doesn't work on this forum.

    Hope this helps.

    Pete

  3. #3
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Fail to compare text in two cells with IF

    See if this works

    =IF(CLEAN(SUBSTITUTE(F2,"Season",""))-E2,"No","Yes")

  4. #4
    Registered User
    Join Date
    04-07-2019
    Location
    Hanoi, Vietnam
    MS-Off Ver
    16001.11425.20056.0
    Posts
    13

    Re: [PROBLEM] Fail to compare text in two cells with IF

    Hi. I have attached the file. Please take the look.
    Attached Files Attached Files
    Last edited by AliGW; 08-13-2019 at 06:31 AM. Reason: Please don't quote unnecessarily!

  5. #5
    Registered User
    Join Date
    04-07-2019
    Location
    Hanoi, Vietnam
    MS-Off Ver
    16001.11425.20056.0
    Posts
    13

    Re: Fail to compare text in two cells with IF

    Quote Originally Posted by jason.b75 View Post
    See if this works

    =IF(CLEAN(SUBSTITUTE(F2,"Season",""))-E2,"No","Yes")
    Hi.
    It works with just one cell G2. Other cells return #VALUE! error.

  6. #6
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Fail to compare text in two cells with IF

    The space after "Season" appears to be different in some rows, a normal space is CHAR(32), but some of yours are CHAR(160) so excel doesn't recognsse them as the same.

    I thought that the CLEAN function would remove this and just leave the number, but this was not correct. As a workaround, this should do it
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  7. #7
    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,780

    Re: Fail to compare text in two cells with IF

    Try this:

    =RIGHT(CLEAN([@[imdb last season]]),1)=CLEAN([@[last season]])
    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.

  8. #8
    Registered User
    Join Date
    04-07-2019
    Location
    Hanoi, Vietnam
    MS-Off Ver
    16001.11425.20056.0
    Posts
    13

    Re: Fail to compare text in two cells with IF

    Actually I can get my thing done with this formula:

    =IF(MID(F2;8;LEN(F2)-7)=TEXT(E2;"0");"yes";"no")

    But what I want to know is why my original formulas not working. Am I wrong with that formula or something I haven't known. Please help me.

  9. #9
    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,780

    Re: Fail to compare text in two cells with IF

    See post #6 for the reason.

  10. #10
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,742

    Re: Fail to compare text in two cells with IF

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Happy with my answer * Add Reputation.
    If You are happy with solution, please use Thread tools and mark thread as SOLVED.

  11. #11
    Registered User
    Join Date
    04-07-2019
    Location
    Hanoi, Vietnam
    MS-Off Ver
    16001.11425.20056.0
    Posts
    13

    Re: Fail to compare text in two cells with IF

    I don't know all those of (at) and braces in the formula but thank you Jason for the reply. So my original formula would work on a normal space character cell isn't it.
    Sorry, the forum doesn't allow me to post special characters so I use the (at) for replacement. Hope you can get those the thing.

  12. #12
    Registered User
    Join Date
    04-07-2019
    Location
    Hanoi, Vietnam
    MS-Off Ver
    16001.11425.20056.0
    Posts
    13

    Re: Fail to compare text in two cells with IF

    Quote Originally Posted by AliGW View Post
    See post #6 for the reason.
    Yeah, I'm writing the reply before the reply of Jason come up. Sorry.

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

    Re: Fail to compare text in two cells with IF

    The first sentence of Post #2 also explains why it didn't work.

    Pete

  14. #14
    Registered User
    Join Date
    04-07-2019
    Location
    Hanoi, Vietnam
    MS-Off Ver
    16001.11425.20056.0
    Posts
    13

    Re: Fail to compare text in two cells with IF

    Ok, thanks for all the help. But I'm still curious of myself. This formula is right isn't it:

    =IF(F2=("Season "&E2);"yes";"no")

    You can compare two strings in a logical statement can't you?
    Many thanks.

  15. #15
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,742

    Re: Fail to compare text in two cells with IF

    Yes, but as Pete_UK said there is a difference between spaces.
    When you are typing formula like your you are using space (standard space if I can say like this) but information which you've got in table can be non-breaking space. So comparison gives FALSE.

  16. #16
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Fail to compare text in two cells with IF

    As I pointed out in post #6. the space in "Season "&E2 is a character 32 space (normal space).

    Some rows in the imdb column have a character 160 space (non breaking space) instead of a character 32 space (normal space).

    160=32 is false, so any row that has a character 160 space will return false regardless of the season number.

  17. #17
    Registered User
    Join Date
    04-07-2019
    Location
    Hanoi, Vietnam
    MS-Off Ver
    16001.11425.20056.0
    Posts
    13

    Re: Fail to compare text in two cells with IF

    Ok, I got it. It's really helpful. Many thanks.

  18. #18
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Fail to compare text in two cells with IF

    Having just replied to another thread with the exact same problem, I'm sitting here asking myself why I didn't offer the same suggestion here as I have just done in that thread.

    Use Ctrl h to replace the non breaking spaces with normal spaces, then original formula should work just fine.

    Enter the non breaking space into the 'Find What' box by holding the Alt key, then typing 0160 on the number pad.
    Enter a normal space into the 'Replace with' box using the spacebar.
    Click 'Replace All'
    Job done

+ 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. How to make a cell display "FAIL" when range of cells is FAIL
    By crazychile in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-18-2017, 04:13 PM
  2. Help with Pass/Fail Problem
    By clooysen in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-28-2016, 09:39 PM
  3. [SOLVED] Need a formula for pass/fail based on no. of Y answers but automatically fail if 3a is N
    By Researcher1111 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 09-15-2013, 10:20 PM
  4. Replies: 2
    Last Post: 01-30-2013, 12:59 PM
  5. Compare two text cells and extract common text words
    By ghost_chip in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-28-2012, 06:07 AM
  6. [SOLVED] Problem with code. (Compare all cells)
    By Metrazal in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-10-2006, 03:34 PM

Tags for this Thread

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