Share via

Excel If statement only returns false

Anonymous
2024-04-16T12:19:36+00:00

Hello,

My issue is this. I want to write a very simple if statement.

Statement should be =if(o2="120","yes","no")

The problem.

When I write this it will always return no. If I change O2 to letters vs a number such as

=if(o2="bat","yes","no")

then if o2 is written as bat it will return yes and if it is not it will return no as expected.

Why is it when I set a cell equal to a specific number value vs a letter value it won't function properly?

Microsoft 365 and Office | Excel | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

4 answers

Sort by: Most helpful
  1. HansV 462.6K Reputation points
    2024-04-16T14:00:40+00:00

    In addition to the reply by Snow Lu:

    If you omit the quotes around a text value, Excel tries to interpret the text value as a cell address, for example AB31, or as a defined name, not as a literal string.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2024-04-16T13:25:02+00:00

    The reason why you need to use "" for text input is because Excel recognizes text as a string of characters, while numbers are recognized as numerical values. When you use "" around text, you are telling Excel to treat it as a string of characters, rather than a numerical value. Therefore, when you compare a cell containing text to a specific value, you need to use "" to indicate that it is a string of characters. However, when you compare a cell containing a numerical value to a specific value, you do not need to use "" because Excel recognizes number as a numerical value by default.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2024-04-16T12:44:39+00:00

    Thank you, I am both delighted and infuriated that worked. Do you know why "" are required for text input but not numbers? Only asking so that I have a better understanding of how to write formulas moving forward.

    Was this answer helpful?

    0 comments No comments
  4. HansV 462.6K Reputation points
    2024-04-16T12:24:57+00:00

    I assume that you want to compare O2 to the number 120. If that is correct, omit the quotes around 120:

    =IF(O2=120, "yes", "no")

    Was this answer helpful?

    0 comments No comments