PDA

View Full Version : IIF Function in VBA



Nishant Choudhary
12-01-2011, 06:46 PM
The Immediate If Function
The Immediate If function has the syntax:
IIf(Expression, TruePart, FalsePart)

If Expression is True, then the function returns TruePart. If Expression is False, the
function returns FalsePart. For instance, the following code displays a dialog indicating
whether or not the first row in the active worksheet is empty:


Dim rng As Range
Set rng = ActiveSheet.Rows(1)
MsgBox IIf(IsEmpty(ActiveSheet.Cells(1, 1)), _
"Cell is empty", "Cell is not empty")

It is very important to note that the Immediate If function always evaluates both TruePart and
FalsePart, even though it returns only one of them. Hence, we must be careful about
undesirable side effects.

Admin
12-01-2011, 08:51 PM
Hi Nishant,

Welcome to ExcelFox !!

Keep share the tips !