Question

I have been looking every where on the net and everyone seems to simply suggest an alternative like SUMPRODUCT, however, I want to use wildcards. Wildcards work fine in COUNTIF but not in other alternatives I have seen.

How can I search every nth cell in a column and return a count of the number of times an exact substring is found (i.e. COUNTIF(range, string), where range is every nth cell and string could be "*somestring", "some string*", "*somestring*" or "some?string")

Was it helpful?

Solution

Yes, SUMPRODUCT is an option - say you want every 5th cell starting at A2 (i.e. A2, A7, A12 etc.) you can use this formula to count instances of "text" in those cells (possibly within other text)

=SUMPRODUCT((MOD(ROW(A2:A1000)-ROW(A2),5)=0)+0,ISNUMBER(SEARCH("text",A2:A1000))+0)

change the 5 to whatever n you want - it always starts with the first cell in the range if you use this syntax.

The ISNUMBER(SEARCH part gives you the equivalent of a "wildcard" search (you can't use actual wildcards here)

update

If you want the equivalent of "text*" then use LEFT function, e.g.

=SUMPRODUCT((MOD(ROW(A2:A1000)-ROW(A2),5)=0)+0,(LEFT(A2:A1000,LEN("text"))="text")+0)

and RIGHT can be used for the equivalent of "*text".

IF you want the equivalent of "t?xt" that would be trickier. The SEARCH function in the first formula will allow you to search for "t?xt" but that would be amongst other text so if you want the entire contents to be "t?xt" you could add another check, e.g.

=SUMPRODUCT((MOD(ROW(A2:A1000)-ROW(A2),5)=0)+0,ISNUMBER(SEARCH("t?xt",A2:A1000))+0,(LEN(A2:A1000)=4)+0)

That will only count cells which contain "text", "toxt", "t5xt" etc. but not "text2"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top