How to use Excels COUNTIF in every nth cell and retain wildcard functionality

此生再无相见时 提交于 2019-12-25 05:09:06

问题


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")


回答1:


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"



来源:https://stackoverflow.com/questions/23084729/how-to-use-excels-countif-in-every-nth-cell-and-retain-wildcard-functionality

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!