Simple pattern with Excel COUNTIF to match a substring?
7,841
Solution 1
concat the regex string and the cell string within the formula as such:
=COUNTIF(A1:A10,"*"&C11&"*")
let me know if this helped
Solution 2
Another option is to use SUMPRODUCT
and FIND
:
=SUMPRODUCT(--(ISNUMBER(FIND(C11,A1:A10))))
Related videos on Youtube
Author by
Thufir
Updated on September 18, 2022Comments
-
Thufir over 1 year
How do I fix this formula:
=COUNTIF(A1:A10,"*jim*")
to match anything containing the sub-string of "jim" but from a cell, as:=COUNTIF(A1:A10,C11)
where cellC11
contains the text "jim"?Perhaps another cell to wrap "jim" with asterisks?
(Surely I don't need to define a special function, or resort to Visual Basic?)
see also:
-
iDevlop over 2 yearsif your question was answered, be correct and validate the right answer
-
-
Thufir about 5 yearsthat looks right, I won't be able to check for at least a day. I think that's at least towards a solution, if not the actual solution. Thanks.
-
Alan about 5 yearsi just tried it out using madeup names and it appears to be working properly
-
Thufir about 5 yearshow would that relate to
regex
forstring
data? -
cybernetic.nomad about 5 yearsNo need for regex, this function looks for the presence of whatever string is in cell
C11
we don't care where it is or if there's more text around it, only that it's present. If it's present,ISNUMBER
returns "True" (1), if not, it returns "False" (0). TheSUMPRODUCT
then adds all the 1s, resulting in a count of all the cells that include the desired string -
Thufir about 5 yearsah, I found: exceljet.net/glossary/double-unary which adds to your answer. Makes more sense, and beautifully simple.