Currently I'm using this formula to count the number of string matches in a range:
=COUNTA(FILTER(D3:D723,FIND(A1, D3:D723)))
If A1="am" and range has "ham", "scammy", "pan"; then the cell will display 2.
It appears to work correctly, except for one thing- it displays a match of 1 if there are no matches. How can I fix this?
You can use:
=COUNTIF(D3:D723,"*"&A1&"*")
It counts the amount of cells in D3:D7243 that have the substring in Cell A1. The * are there as a wildcard in front and behind the substring.
I made a working example for you as well to look at.
UPDATE: fixed statement
This is the formula you are looking for.
Formula
=COUNTA(IFERROR(FILTER(B:B,FIND(IF(A1="",(1/0),A1), B:B))),"")
Results
Search for A:
Search for empty string:
Search for am:
Example
I've created an example file you you: Counting String Matches in a Range
Related
I'm struggling with writing the proper syntax for this formula in Google Sheets. In one sheet called Game Log, in the H column I have data that can be a range of names (1 - 10 names per row). I'm trying to construct a COUNTIF statement that would search for the name in all the rows for that column. There can be several other names in the same column so I need to use the wildcard * to find any occurrence of the name in each row. So for example, the current code below would count all occurrence of Adam in the rows.
=COUNTIF('Game Log'!H3:H102, "*Adam*")
What I would like to do is replace the hard codes "Adam" with a cell reference (in this case B2). Is it possible to combine that cell reference with the wild card? The know the code below doesn't work (as it would return text counting occurrences of B2), but is something like this possible?
=COUNTIF('Game Log'!H3:H102, "*B2*")
Have you tried something like this?
=COUNTIF('Game Log'!H3:H102, "*" & B2 & "*")
That ought to look for any string value, followed by the cell value, followed again by any string value. It's essentially just performing separate checks, in sequence, which allows you to search for different value types (in this case string wildcard + cell value + string wildcard).
I need help returning a text value "WIP" based on column A matching an entire range.
The range has digits which users will input that match column A but cells will have more than 1 digit which will be seperated by a comma.
I'm not clear on how to do this so i'm stuck somewhere with:
Sumproduct, isnumber, and match yet i'm struggling how to yield a result.
Could you please help?
Thanks a lot!
Spreadsheet link: https://docs.google.com/spreadsheets/d/1XcIql3ZMymqipZsGUyBk3_ze6LMzjQtHTF-ylGDIT_A/edit#gid=0
Output highlighted in yellow
You can try:
=ArrayFormula(IF(Isnumber(MATCH(A9:A38,FLATTEN(SPLIT(FLATTEN(IF(LEN(G8:M18),G8:M18,)),",")),0)),"WIP",))
I have a cell with a variable number of substrings separated by a comma.
To search:
"first,second,third"
"primero,segundo,tercero,cuarto"
"eins,zwei"
and I have a column with many strings that are composed by some of the substrings:
Column with full items
"first,second,third,fourth"
"primero,segundo,tercero,cuarto,quinto"
"primero,tercero,cuarto"
"eins,zwei,drei"
...and so on...
I would like to find the items of the Column above which has the substrings to be searched. Not a big issue when the amount of substrings is fixed but when it varies it becomes harder. I have a horrible formula that counts the number of commas and then it uses IF for each amount of substrings to search and several FIND(index(SPLIT(A4,","),2) for each substring. The formula is gigant and hard to handle.
Can you think of a better way of doing it?
Here there is an example of what I would like to do. The blue cells are the ones that should have the formula.
https://docs.google.com/spreadsheets/d/1pD9r4JF48cVSNGqA4D69lSyasWxTvAcOhWWu1xW2mgw/edit?usp=sharing
Thanks in advance!
Thank you all for your help! In the end, I used the QUERY function.
=QUERY(E:F,"select E where F contains '" & textjoin("' AND F contains '",TRUE,split(A2,",")) &"'" )
If you are interested, you can see the solution applied in the original spreadsheet :)
I have a range of cells in one column, some contain text and some are blank cells. I want to search the range for the first occurrence of a word. I know that it's possible to combine Index and Match functions to find exact text within a range of cells. But I need to search for partial matches. I've tried mixing using the Search function, but it doesn't seem to accept a range. How can I search a range for the first partial text match? I only want to use formulas, not script.
The search function can be applied to a range using arrayformula wrapper:
=arrayformula(search("str", C2:F9))
This returns a bunch of #value! errors where no match is found, or the position of substring when it's found. A more readable output is produced with
=arrayformula(if(iserror(search("str", C2:F9)), , C2:F9))
This leaves non-matches blank, and returns the actual cell content where there is a match. Or you could put row(C2:F9) at the end to get the row numbers, etc.
We can simply use vlookup or match formula to find a string from a specific range
Vlookup example:
=VLOOKUP(B2, $B$2:$B, 1, FALSE)
Match example:
=MATCH("Sunday",A2:A9,0)
=MATCH(DATE(2012,1,1),A2:F2)
I have a column XXX like this :
XXX
A
Aruin
Avolyn
B
Batracia
Buna
...
I would like to count a cell only if the string in the cell has a length > 1.
How to do that?
I'm trying :
COUNTIF(XXX1:XXX30, LEN(...) > 1)
But what should I write instead of ... ?
Thank you in advance.
For ranges that contain strings, I have used a formula like below, which counts any value that starts with one character (the ?) followed by 0 or more characters (the *). I haven't tested on ranges that contain numbers.
=COUNTIF(range,"=?*")
To do this in one cell, without needing to create a separate column or use arrayformula{}, you can use sumproduct.
=SUMPRODUCT(LEN(XXX1:XXX30)>1)
If you have an array of True/False values then you can use -- to force them to be converted to numeric values like this:
=SUMPRODUCT(--(LEN(XXX1:XXX30)>1))
Credit to #greg who posted this in the comments - I think it is arguably the best answer and should be displayed as such. Sumproduct is a powerful function that can often to be used to get around shortcomings in countif type formulae.
Create another list using an =ARRAYFORMULA(len(XXX1:XXX30)>1) and then do a COUNTIF based on that new list: =countif(XXY1:XXY30,true()).
A simple formula that works for my needs is =ROWS(FILTER(range,LEN(range)>X))
The Google Sheets criteria syntax seems inconsistent, because the expression that works fine with FILTER() gives an erroneous zero result with COUNTIF().
Here's a demo worksheet
Another approach is to use the QUERY function.
This way you can write a simple SQL like statement to achieve this.
For example:
=QUERY(XXX1:XXX30,"SELECT COUNT(X) WHERE X MATCHES '.{1,}'")
To explain the MATCHES criteria:
It is a regex that matches every cell that contains 1 or more characters.
The . operator matches any character.
The {1,} qualifies that you only want to match cells that have at 1 or more characters in them.
Here is a link to another SO question that describes this method.