....
Changing arguments for clarity.
How would this formula compare efficiency-wise?
=SUMPRODUCT(COUNTIF(range,"*"&REPT(char&"*",instance_array)))
....
My formula would loop through range 5 times: the first LEN call, the
LOWER call, the SUBSTITITE call, the second LEN call, and the final
SUMPRODUCT call. However, my SUBSTITUTE call would only iterate
through range once, and perform a simple operation - effectively
deleting all w's.
Your formula would iterate through range as many times as there are
entries in instance array for the COUNTIF call, in your example 3
times. However, processing a range with COUNTIF where the second
argument contains wildcards isn't as simple as my SUBSTITUTE call. If
COUNTIF special cases patterns in which the first, last or both chars
are *, then COUNTIF should process the pattern "*w*" at least as fast
as SUBSTITUTE(range,"w","",1) would, and probably faster. However,
it's unlikely COUNTIF special cases patterns with *'s between literal
characters. When those occur, you need significantly more logic FOR
EACH entry in range, approximating an inner loop.
Your formula as you wrote it could effectively require 6 iterations
through range: once for "*w*", effectively 2 for "*w*w*", and
effectively 3 for "*w*w*w*". That is, if R were the number of entries
in range, A were the number of sequential entries in instance_array,
then my formula would be O(N) with a large constant (c), but yours
would be O(N A^2) with a small constant (d). As long as c > d A^2,
yours would be faster. But as soon as c < d A^2, mine would be faster.
I'd guess yours would always be faster for A = 2, usually faster for A
= 3 except when most entries in range have at least 2 w's, and seldom
if ever faster for A >= 4.