Quote Originally Posted by snb View Post
You shouldn't call a function if it shouldn't be applied.
You shouldn't test that after calling the function, but before
Agree, but since the functionality was required in multiple places, I opted to simplify the lines where it was used by putting the IIF() in the function

The largest savings I've seen for 'testing first' is when using Replace().


https://www.aivosto.com/articles/stringopt.html#whyslow


Replace or not?

The following tip might be obvious, but it wasn't to us. It makes no sense to call Replace if you're not likely to replace anything. Replace runs slowly. Replace always creates a copy of the input string, even if no replacement occurs, and making the copy is slow. If a replacement is unlikely, verify first (with InStr or InStrB, for example) that there is something you need to replace.

If InStr(Text$, ToBeReplaced$) <> 0 Then
Text$ = Replace(Text$, ToBeReplaced$, "xyz")
End If

If a replacement is likely or certain to occur, there is no need to call InStr. It just adds an extra burden.