Excel: Find letter in cell range containing strings and count occurrance - excel

I've got a cell range A1:A10 containing single letters or short strings like "GEPR", "GE" etc. and want to count every cell containing a G.
I tried
=IFERROR(IF(FIND("G";A1);1);0)
but this writes a 1 into each row and doesn't output the sum of cells containing a "G". Furthermore if I want to count for another letter (e.g. "E") I need more space in the worksheet. Is there a more convenient function like COUNTIF which just needs one cell for each leter?

You can use SUMPRODUCT together with FIND to do this.
=SUMPRODUCT(--NOT(ISERROR(FIND("G",$A$1:$A$10))))
This basically counts for how many values in A1:A10 the FIND function does not return an error.

Assuming you don't care about case just use COUNTIF with "wildcards", e.g. for the number of cells in your range containing a "G"
=COUNTIF(A$1:A$10,"*G*")
If you want to use a cell reference for the criterion, e.g. with C2 containing "G" you can use this version:
=COUNTIF(A$1:A$10,"*"&C2&"*")

You might put the letters of interest in Row1 (staring at B) and in B2 and copied across:
=SUM(IFERROR(IF(FIND(B$1;$A2:$A11);1);0))
entered with Ctrl+Shift+Enter.

Related

Search rows for string between characters and sum

Let’s say I have a column wherein there are blank rows and rows that combine text and numbers. For example, A1 might look like "some text (2)", A2 might contain "some more text (7)", A3 might be blank and A4 look like A1 and A2. I would like to be able to quickly find the sum of the numbers in between the parentheses in column A. I have figured out how to use the MID, LEFT, and FIND functions to extract the values from each string, but getting their sum amounts to an extremely long formula (considering the column might contain as many as twenty such cells). This is what I have been using:
SUM(IFERROR(MID(LEFT(A1,FIND(")",A1)-1),FIND("(",A1)+1,LEN(A1)), 0) +
IFERROR(MID(LEFT(A2,FIND(")",A2)-1),FIND("(",A2)+1,LEN(A2)), 0)+...
And so on, down to the last desired row. This is far too tedious. Is there a shorter way?
You can use an array formula:
=SUM(1*IFERROR(MID(LEFT($A$1:$A$20,
FIND(")",$A$1:$A$20)-1),FIND("(",$A$1:$A$20)+1,LEN($A$1:$A$20)), 0))
Enter using Ctrl+Shift+Enter
E.g:

Excel: count values on another sheet with dynamic column reference

I have a simple formula in cell B7 of a sheet called Summary Stats that references a sheet called Rolling Returns Data:
=COUNT('Rolling Returns Data'!C$11:C$17202)
I want to be able to dynamically reference the column in the formula i.e. I have letter C in cell B1 of the Summary Stats sheet and want to be able to replace the reference to column C in the formula with a reference to cell B1, so that if I then change the formula that calc. that is then being performed is:
=COUNT('Rolling Returns Data'!D$11:D$17202)
As Scott Craner suggested, use INDIRECT.
=COUNT(INDIRECT("'Rolling Returns Data'!"&A1&"$11:"&A1&"$17202"))
Now you just have to put the letter of the column you want to reference. You can of course change the A1 reference to anything you'd like. Or you can change the code to the following
=COUNT(INDIRECT("'Rolling Returns Data'!"&A1))
and use A1 to specify the address of your column, in this case "C$11:C$17202".
If you're ok using column numbers rather than column letters then this non-volatile formula will work:
=COUNT(INDEX('Rolling Returns Data'!1:17202,11,$B$1):INDEX('Rolling Returns Data'!1:17202,17202,$B$1))
If you really want to use column letters then you can turn a column letter into a column number using:
=COLUMN(INDIRECT($B$1 & 1))
But then you lose the non-volatile nature.
Edit:
If you use the column numbers and leave B1 blank it will return the count of all columns.

Count Cell if value in Column A is 1

I'm looking to get my formula to work. I want it to count how many cells in column G contain 6/7/8, but only if the cell in Column A contains a 1.
That is what I currently have.
{=SUM(IF(A4:A72=1,1,0) AND IF(G4:G72="6/7/8",1,0))}
If you're just looking for a count, using Countifs will be helpful. Since it's a simple comparison on cell A1, I'd put it in an If statement like so:
=IF(A1=1,COUNTIFS(G:G,"6/7/8"),FALSE)

Excel - count multiple words per cell in a range of cells

I have some cells with multiple names in them as so:
Names are not repeated in the same cell.
I have some more cells below where I need to count how many times each name appears in each column. The names of the people counted above are to the right in one column, and the number of times each name appears should be calculated in the corresponding row of the next column.
For example, the cells that read 2 and 0 should read 4 and 4 (for the amount of times they appear in the previous image).
Here is an example of the desired result:
What formula should I use to accomplish this?
You can use an array formula (Ctrl+Shift+Enter) for this. Set up your list of names somwhere (For example, F1, F2, F3 ...) then next to it (in G1):
{=COUNT(IFERROR(FIND(F1,A:A,1),FALSE))}
Assuming A is you names column. Than simply drag G1 down to copy for all names.

Count number of blank cells in row between last cell and next non-blank cell

Is it possible (with a formula preferably) to count the number of blank cells in row, where the counting starts at a given column and counts going backward (e.g. right to left) the number of blank cells until a non-blank cell is found? In the example below, the counting begins at Column H and proceeds leftward. Using COUNTA or COUNTIF seem like reasonable tools to use, but I am unsure on how to terminate the counting once a non-blank cell is found.
You can use something like this if the values in your table are all text:
=COUNTBLANK(INDIRECT(CHAR(97+MATCH("zzzz",B2:H2))&ROW()&":H"&ROW()))
MATCH("zzzz",B2:H2) returns the column number in which the last non-blank cell is.
CHAR(97+ column number) returns the letter of that column.
Append it to the row number to give the reference where the COUNTBLANK has to start with &ROW()
&":H"&ROW()) gives the reference of the last cell, which is H plus the row number.
INDIRECT turns the concatenated text into a range that Excel can evaluate.
Try this formula
=COLUMNS(B2:H2)-MATCH("zzzz",B2:H2)
You could use nested if statements
=IF(ISBLANK(H2),IF(ISBLANK(G2),IF(ISBLANK(F2),IF(ISBLANK(E2),IF(ISBLANK(D2),IF(ISBLANK(C2),IF(ISBLANK(B2),IF(ISBLANK(A2),8,7),6),5),4),3),2),1),0)

Resources