Share via

IF Statement comparing text

Les M 80 Reputation points
2026-01-20T11:57:14.6866667+00:00

When comparing string value in an IF statement, does it matter if the string is all uppercase or not?

EXAMPLE: IF lastname = "Doe" OR lastname = "DOE" Then.....

I am just wondering if it matters or do I actually need to check both like the above code is doing.

Microsoft 365 and Office | Excel | For business | Windows
0 comments No comments

4 answers

Sort by: Most helpful
  1. JeovanyCV 470 Reputation points Volunteer Moderator
    2026-01-31T02:40:55.04+00:00

    Hi Les M

    Here is another formula option/solution =IF(LOWER(C2)="doe","Yes","No")

    User's image

    I hope this helps you

    Thanks

    Kind regards

    Jeovany CV

    Was this answer helpful?

    0 comments No comments

  2. Dana D 90 Reputation points
    2026-01-21T21:12:46.77+00:00

    Oops. Sorry. Looks like you wanted vba.

    Was this answer helpful?


  3. riny 20,950 Reputation points Volunteer Moderator
    2026-01-20T16:27:33.6233333+00:00

    Not sure why you accepted a nonsense AI answer. IF in Excel is NOT case sensitive. Try it and you'll see for yourself. Though, there are functions that are case sensitive in Excel. For instance, FIND is but SEARCH is not. Please un-accept the AI answer and delete it.

    Was this answer helpful?


  4. AI answer

    2026-01-20T11:57:21.4866667+00:00

    When comparing string values in an IF statement, it does matter whether the strings are in uppercase or lowercase unless you specify a case-insensitive comparison. In many programming languages, string comparisons are case-sensitive by default, meaning that "Doe" and "DOE" would be considered different strings.

    To avoid having to check both variations, you can use a case-insensitive comparison method. For example, in Visual Basic, you can use the Option Compare statement to set the comparison mode to case-insensitive, or you can explicitly use a method that allows for case-insensitive comparison. This way, you can write your IF statement without needing to check both cases separately.

    In summary, if you want to treat "Doe" and "DOE" as equal, you should use a case-insensitive comparison method instead of checking both conditions separately.

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.