+ Reply to Thread
Results 1 to 3 of 3

My IF function is not recognizing the results of my LEFT function.

  1. #1
    Registered User
    Join Date
    03-23-2012
    Location
    Boston, MA
    MS-Off Ver
    Excel 2010
    Posts
    7

    My IF function is not recognizing the results of my LEFT function.

    Wow, I'm so frustrated! Example spreadsheet is attached.

    Why does the following formula return "False," instead of "True."

    Formula in cell A1:
    =IF(B1=C1,"True","False")

    Value in B1:
    2

    Formula in C1:
    =LEFT(D1,1)

    Value in D1:
    2

    Result = "False" whaaaaat?

    If I replace the 2 with a text character it works fine:

    Formula in cell A1:
    =IF(B1=C1,"True","False")

    Value in B1:
    "F"

    Formula in C1:
    =LEFT(D1,1)

    Value in D1:
    "F"

    Result = "True" --- why does text work and not the number?!?! Typing the number in works fine and I tried matching up the formatting to see if that did it, no luck.

    Here's my dilemma in more detail (if you can answer the above read no further): I'm trying to isolate all the values in a series of text strings that start with a certain digit, and end with certain digits, specifically I'm trying to test a string to see if the last 4 characters of a string are equal to 2012, and the first character is a 2. For example the bold entries would qualify:

    1022012
    1162012
    1232012
    1242011
    1302012
    2062012
    2132012
    2202012
    2272012
    3052012
    3122012

    I can't sort the list because values from 2011 are dispersed throughout.

    So I have the following formula, which references two place holder cells that I can input the month and year I'm looking for referencing two cells that contain the month and date I'm currently looking for:

    =IF(AND(LEFT(E4,1)=H2,RIGHT(E4,4)=I2),"True","False")

    Where H2 has the "Month" value in it, in this case 2, and I2 has the year value, in this case 2012.

    Thanks!
    -Tim
    Attached Files Attached Files

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: My IF function is not recognizing the results of my LEFT function. =IF(AND(LEFT(E4,1)=

    Hi Tim, welcome to the forum.

    When using IF and comparisons using =, the two values must be identical for a match to occur. The value (number) 2 is not the same as the text string "2". Anytime you use a LEFT, MID, RIGHT function the result is a String, not a number.

    So you could use something like:

    =IF(AND(LEFT(E4,1)+0=H$2,RIGHT(E4,4)+0=I$2),True,False)

    The +0 converts a string containing a number to an actual number, which should match. Also, True and False don't need to be in quotes. An IF function will return True or False automatically unless you have some other value or function in those arguments.

  3. #3
    Registered User
    Join Date
    03-23-2012
    Location
    Boston, MA
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: My IF function is not recognizing the results of my LEFT function.

    Paul, many thanks! I tried changing the formatting to a number manually for the result, thinking that it was a formatting issue, but it appears that you can't change the formatting of a formula result through the settings. I'm glad to know that you can use the "+0" to force it.

    Thanks so much!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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