I am trying to use the IIF function in the code below but it gives me a Compile error that states that "Variable [is] not defined". It highlights the "Zero" in fifth line of code:
Option Explicit
Sub macro()
Dim ws As Worksheet
With ThisWorkbook.Worksheets("Sheet1")
MsgBox IIf(ws.Range("A1") = 0, “Zero”, “Nonzero”)
End With
End Sub
I don't know why it's pulling this error as I thought that the range of a cell does not have to be defined. I also tried defining the Range as a variable but that did not resolve it either.
What would be the problem here?
wsWithblock has no effect here. Remove thewsdeclaration, and replacews.Rangewith.Range.