IIf Function
Thanks Mike.
I think that I read that somewhere.
Is there a clear example then of when one would need the IIf function?
--
Ken Hudson
"Mike H" wrote:
Hi,
In your simple example both snippets evaluate the same but consider this
equally simplistic example
Var1 = IIf(Len(Range("A1")) 0, "Yes", 22 / 0)
Even if this evaluates as TRUE (Len(A1)0) you will still get an error
(Div/zero) because in IIF both parts are evaluated unlike an If/then
statement where evaluation stops as soon as a condition satisfies the
statement.
If Len(Range("A1")) 0 Then
Var1 = "Yes"
Else
Var1 = 22 / 0
End If
Would work if A10
Mike
"Ken Hudson" wrote:
I just ran across the IIf function and am trying to clarify its usage.
I would normally write:
It looks like I could write:
Var1 = IIf(Len(Range("A1")) 0, "Yes" , "No")
Is my logic correct?
Would this be the principle use of that function, to shorten the coding
required in my example? Or is this function used in some other types of cases?
--
Ken Hudson
|