The Problem (Q-score 26, ranked #10th of 95 in the VBA Core archive)
The scenario as originally posted in 2010
I’m trying to get a lazy evaluation with ‘And’ in my Excel macro by doing the following:
If Not myObject Is Nothing *And* myObject.test() Then
'do something'
Else
'do something else'
End If
I know lazy evaluation exists in VB.NET as AndAlso and OrElse but cannot find anything similar in VBA. If lazy evaluation does not exist in VBA, what’s the best way to structure the code so that it will evaluate the way I expect?
Why community consensus is tight on this one
Across 95 VBA Core entries in the archive, the accepted answer here holds elite answer (top 10 %%) status — meaning voters are unusually aligned on the right fix.
The Verified Solution — elite answer (top 10 %%) (+36)
8-line VBA Core pattern (copy-ready)
The only short circuiting (of a sort) is within Case expression evaluation, so the following ungainly statement does what I think your asking;
Select Case True
Case (myObject Is Nothing), Not myObject.test()
MsgBox "no instance or test == false"
Case Else
MsgBox "got instance & test == true"
End Select
End Sub
Error-handling details to lift with the snippet
This answer wires error flow through MsgBox / Err.Description. Keep that intact: stripping it to “make it cleaner” removes the signal you’ll need when the macro fails silently on a user machine.
When to Use It — vintage (14+ years old, pre-2013)
A top-10 VBA Core pattern — why it still holds up
Ranks #10th of 95 in the VBA Core archive. The only pattern ranked immediately above it is “Code to loop through all records in MS Access” — compare both if you’re choosing between approaches.
What changed between 2010 and 2026
The answer is 16 years old. The VBA Core object model has been stable across Office 2013, 2016, 2019, 2021, 365, and 2024/2026 LTSC, so the pattern still compiles. Changes that might affect you: 64-bit API declarations (use PtrSafe), blocked macros in downloaded files (Mark-of-the-Web), and the shift toward Office Scripts for web-first workflows.