Take all your problems and rip them apart:
If C2=R2 and D2 is < T2 then U2, if D2 is >T but T3 but < T4 then U4 if D2 is > T4 but < T5 then U5, if D2 is > T5 but < T6 then U6 BUT if C2 does not equal R2 then S8
Start with this using NA()
to represent parts which haven't been completed yet (this will show the #N/A
value in the cell):
=IF(C2=R2,NA(),S8)
Add the lookup based on D2:
=IF(C2=R2,IF(D2<T2,U2,NA()),S8)
Assuming that the next part is D2 > T2 and D2 < T3 (althought strictly this formula says D2 >= T2) and result is U3:
=IF(C2=R2,IF(D2<T2,U2,IF(D2<T3,U3,NA())),S8)
Now add between T3 and T4:
=IF(C2=R2,IF(D2<T2,U2,IF(D2<T3,U3,IF(D2<T4,U4,NA()))),S8)
Between T4 and T5:
=IF(C2=R2,IF(D2<T2,U2,IF(D2<T3,U3,IF(D2<T4,U4,IF(D2<T5,U5,NA())))),S8)
Finally between T5 and T6:
=IF(C2=R2,IF(D2<T2,U2,IF(D2<T3,U3,IF(D2<T4,U4,IF(D2<T5,U5,IF(D2<T6,U6,NA()))))),S8)
We still have NA()
because you haven't defined the behaviour for C2=R2 and D2 >= T6
As Stobor said in the comment to your original question, using VLOOKUP
would be much better - see http://office.microsoft.com/en-us/excel/HP052093351033.aspx for details
Your current structure in the T and U columns won't work with VLOOKUP
because:
the next largest value that is less
than lookup value is returned
This would mean that VLOOKUP
would return U3
when you wanted U2
, U4
instead of U3
and so on. To solve this you would need to move all of the entries in the U column down by one row, put a dummy value or =NA()
into U2 and create a value in T7 that was greater than the existing value in T6