Hi All,
Is it illegitimate for VBA to use "SET" statement with "iif" ?
I got an error for the below coding︰
Is that the only correct writing is as follows?
My reason of combining "SET" with "IIF" mainly is to simplify the code length for better readability.
If that is disallowed in VBA, I will stick to the "If Then Else" statement.
Thanks all.
Is it illegitimate for VBA to use "SET" statement with "iif" ?
I got an error for the below coding︰
Code:
Dim Rng As Range, URng As Range
Set URng = Nothing
Set Rng = Range("A1")
Set URng = IIf(URng Is Nothing, Rng, Union(URng, Rng))
MsgBox URng.Address(1, 1)
Is that the only correct writing is as follows?
Code:
Dim Rng As Range, URng As Range
Set URng = Nothing
Set Rng = Range("A1")
If (URng Is Nothing) Then
Set URng = Rng
Else
Set URng = Union(URng, Rng)
End If
MsgBox URng.Address(1, 1)
My reason of combining "SET" with "IIF" mainly is to simplify the code length for better readability.
If that is disallowed in VBA, I will stick to the "If Then Else" statement.
Thanks all.