PDA

View Full Version : If statement logic question



doctortt
04-09-2011, 11:36 PM
Can a guru take a look at the codes for me below? If VariableX is 80, will Excel do both A and B or just B? Thanks

If VariableX <= 100 Then
Do A
Elseif VariableX <= 200 Then
Do B
so on......

End If

shrivallabha
04-09-2011, 11:49 PM
It will not do both as long as, you are referring to a single continuous If construct. The if loop will be complete when one of the condition defined is met.

If you are working on the example like you have shown above, you may also consider using Select Case in the ascending mode:
Select Case VariableX
Case Is <= 100
'Do something
Case Is <= 200
'Do something
Case Is <= 300
'Do something
Case Else
End Select

Bob Phillips
04-10-2011, 09:45 PM
Can a guru take a look at the codes for me below? If VariableX is 80, will Excel do both A and B or just B? Thanks

If VariableX <= 100 Then
Do A
Elseif VariableX <= 200 Then
Do B
so on......

End If

It won't so both, as testing would show. Stepping through the code would show exactly what it does do.