vendredi 26 janvier 2018

excel IF with "blank digit"

I have in Excel cell A1 containing a string with numbers separated by spaces and a dash, such as 8 - 13 and I need to find which number is larger, or if they are equal. I extract the number values to their own cells B1 and C1 with =LEFT(A1;2) and =RIGHT(A1;2). I then compare B1 and B2 in cell D1, =IF(B1 > C1; "left"; "right") to find which number is larger - and that's where I fail. Value in B1, 8, is clearly not greater than value in C1, 13, yet formula in D1 returns "left".

This seems to be caused by taking two digits with LEFT, when there is only one number there. If I type "8" in B1 in stead of the function, C1 correctly returns "right".

Either or both of the values in A1 may be one or two digits long. How can I make IF work as intended?

Aucun commentaire:

Enregistrer un commentaire