How to use the VBA IIF Function (Syntax + Example)

HomeVBA Functions LIST (Category Wise)How to use the VBA IIF Function (Syntax + Example)

The VBA IFF function is listed under the logical category of VBA functions. When you use it in a VBA code, it evaluates the value supplied for a condition and returns a value is the condition is TRUE else the other value if that condition is FALSE. It’s just like the IF function in the worksheet.

Table of Content Close

Syntax

IIf(Expression, TruePart, FalsePart)

Arguments

  • Expression: The condition which you want to test.
  • TruePart: The value to return if “Expression” is TRUE.
  • FalsePart: The value to return if “Expression” is FALSE.

It’s better to use VBA IF statement instead of IIF as it makes code hard to read.