I am trying to find out the right if statement to use for this task:
if B5 is higher than C5 = 1
if B5 is within 2% higher than C5 = 2
if B5 is lower than C5
Just to make sure I understand correctly, when B5 is within 2% of C5 (either greater than, equal to, or less than), should the formula return "2"? If so, you can use the following formula:
=IF(ABS(B5-C5)<=C5*0.02,2,IF(B5>C5,1,3))
This formula returns "2" when B5 is exactly 2% less than or exactly 2% greater than C5. If you want it to return "3" and "1" in these cases respectively, you can use the following instead:
=IF(ABS(B5-C5)<C5*0.02,2,IF(B5>C5,1,3))
I haven't used excel for years, so I'm not sure as to the exact syntax, but you can you nested if-else statements to achieve this sort of thing. i.e. something to the effect of:
if (B5 is within 2% higher than C5)
print 2
else if (B5 is higher than C5)
print 1
else
print 3
You can nest IF formulae:
=IF(condition2, 2, IF(condition1, 1, IF(condition3, 3, "error!")))
With your conditions, it looks something like:
=IF(AND(B5>(C5-(C5*2/100)), B5<(C5+(C5*2/100))), 2, IF(B5>C5, 1, 3))