I need to use iif()
for my case of checking and assigning values like:
Range(\"A1\").Value = IIf(IsNull(Range(\"A2\").Value), MsgBox(\"1\"), MsgBox(
The VBA documentation for IIf states that it executes both True and False conditions regardless of its output.
You need code similar to the following:
Dim Result as Integer
If IsNull(Range("A2").Value) Then
Result = MsgBox("1")
Else
Result = MsgBox("2")
End If
Range("A1").Value = Result
Alternatively, if you're looking for an one-liner:
Range("A1").Value = MsgBox(IIf(IsNull(Range("A2").Value), "1", "2"))
Though this doesn't allow you to change the other MsgBox
parameters as easily as the block-If.