7 Replies Latest reply: Apr 19, 2016 4:21 PM by Ali Ahmad

# Nested IF only work on first condition

Trying to use a Variable to change sheets when a timer hits a certain amount of seconds. Written this IF statement which comes out "ok" as an expression, but only the first condition works. The 0 or 1. Not the condition for 2, 3, 4, 5 etc. Any ideas? Probably something simple I've overlooked.

 =

if(vTimerSec >= 5, 1,

 if(vTimerSec >= 10, 2,
 if(vTimerSec >= 15, 3, if(vTimerSec >= 25, 4, if(vTimerSec >= 35, 5

,0)))))

• ###### Re: Nested IF only work on first condition

All of the conditions you have listed are > 5, so only the first line is actioned.

• ###### Re: Nested IF only work on first condition

Try

If (vTimerSec >= 35, 5,

If (vTimerSec >= 25, 4,

If (vTimerSec >= 15, 3,

If (vTimerSec >= 10, 2,

If (vTimerSec >= 5, 1,

0))))) ;

• ###### Re: Nested IF only work on first condition

It works as supposed, because >=10 is also >=5 and so on...

• ###### Re: Nested IF only work on first condition

try ascending order ...he ranges 35 to 5

• ###### Re: Nested IF only work on first condition

Hi Ali,

Can you please try below and let me know if it works.

if(vTimerSec >= 5 and vTimerSec < 10, 1,

if(vTimerSec >= 10 and vTimerSec < 15, 2,

if(vTimerSec >= 15 and vTimerSec < 25, 3,

if(vTimerSec >= 25 and vTimerSec < 35, 4,

if(vTimerSec >= 35, 5

,0)))))

Thanks,
Sreeman.

• ###### Re: Nested IF only work on first condition

That will work, but if you apply the test against the largest value first and the rest in descending order you only need to test for one condition on each row not two tests.

• ###### Re: Nested IF only work on first condition

Thanks for the help Colin and Sreeman! Really appreciate it. Such a easy twist to it made it work