Very eastern test
? iif(true, 1, 1/0) 'run-time error: division by zero
I assume that you really mean iif () - in VBA it is not a "short circuit", so you should use If..Then..Else..End If in cases where this can be a problem.
Ok - testing what you really asked:
'In a VBA module Function TruePart() MsgBox "True part" TruePart = "True" End Function Function FalsePart() MsgBox "False part" FalsePart = "False" End Function
In cell: =IF(TRUE,truepart(),falsepart())
Get only one msgbox to calculate IF () cell.
As an additional check, this gives you two msgbox - one for each:
Sub Tester() Debug.Print IIf(True, TruePart(), FalsePart()) End Sub
Tim williams
source share