Forum Discussion
Philippe
Aug 02, 2017Copper Contributor
help with coding via comparison operators!
Hello, I've got a data set of about 1000 cells that I'm trying to have excel lump into categories. This is my coding sequence: Age 65-74 - 0 75-84 - 1 85-94 - 2 95+ - 3 I'm strug...
SergeiBaklan
Aug 03, 2017Diamond Contributor
That's interesting how initial formula
=IF(64>H2<=74,1,0)
works.
First, it compares 64 with H2 and returns TRUE or FALSE, doesn't matter. After that it compares the result with 74. Logical TRUE or FALSE are both always less than any number, thus the result is always FALSE.
=IF(FALSE,1,0)
Finally we have always zero.
We may convert first logical into the number
=IF( --(64>H2)<=74,1,0)
which compares 0 or 1 with 74, result is always TRUE.
Finally we have always 1 in this case.
Very often Excel automatically converts logical TRUE/FALSE into the number in formulas, thus you don't need double dash. Not in such case.