Function Foo(thiscell As Range) As Boolean
Foo = thiscell.hasFormula And (InStr(1, UCase(Split(thiscell.formula, Chr(40))(0)), "bar") > 0)
End Function
This function exists to test for the presence of a certain substring (bar, in this case) before the (.
The case I’m having trouble with is when the cell passed into the function is empty, the thisCell.hasFormula is false, but the statement after the and is still being evaluated. This gives me a subscript out of range error in runtime.
Does VBA actually continue evaluating the second argument to the And, even when the first was false?
What you are looking for is called “short-circuit evaluation“.
VBA doesn’t have it.
You can see an approach that is probably adaptable to your situation here.
The approach that was chosen there involved substituting a
Select Casefor theIf. There is also an example of using nestedIfs.