Forum Discussion

Y2135's avatar
Y2135
Copper Contributor
Sep 22, 2022

Excel if have problem.

Hi everyone, please help me, I don't know why my if so weird, for example I type:

Cat     =IF(A3>="Cat",1, IF(A3>="Dog",2, IF(A3>="Bird",3,4)))

Dog    =IF(A4>="Cat",1, IF(A4>="Dog",2, IF(A4>="Bird",3,4)))

Bird     =IF(A5>="Cat",1, IF(A5>="Dog",2, IF(A5>="Bird",3,4)))

But when I enter, it shows me like this:

Cat     1

Dog    1

Bird     3

So, what is this happening, if anyone knows what problem is, please tell me how to fix it, I'm here to thank you in advance.

5 Replies

  • alannavarro's avatar
    alannavarro
    Iron Contributor
    Because you are comparing strings. What excel is doing is sorting the strings like this:
    1 Bird
    2 Cat
    3 Dog

    So, in the second if, is comparing Dog > Cat that would be 3 > 2 that is True , so is returning 1.
    • sivakumarrj's avatar
      sivakumarrj
      Brass Contributor


      Your formula is correct only thing there is no need to add < or > as it requires only in Number as text does not have any value.  So simply apply the same formula without < or >.
       =IF(A3="Cat",1,IF(A3="Dog",2,IF(A3="Bird",3,4)))

    • alannavarro's avatar
      alannavarro
      Iron Contributor
      Sorry, forgot to explain that is sorting the strings in alphabetic order.
      • Y2135's avatar
        Y2135
        Copper Contributor
        Ok, so how do I use if to type like this:
        Cat 1
        Dog 2
        Bird 3

Resources