How to Count number of text instances in excel? - excel

I have a table of my workdays and I want to count instances of word 'work' in each row.
I have a table like this:
I used this code in J1 cell but it doesn't work.
=SUM(IF(2:2 = "Sleep",1,0))
I have found this formula in microsoft's website but it doesn't work.
What is causing this problem?

You need to use the COUNTIF function.
=COUNTIF(C2:I2,"Sleep")
This goes in Cell J2
From Excel's Help
The COUNTIF function counts the number of cells within a range that meet a single criterion that you specify. For example, you can count all the cells that start with a certain letter, or you can count all the cells that contain a number that is larger or smaller than a number you specify.
When in doubt, press the magic button F1 in Excel. :)

Just came across a similar thing in a worksheet and came to google before I remembered why it didn't work.
The countif statement above is perfectly fine, however the original formula given wouldn't have worked as to use a sum in this way means you have to make it an array or CSE Formula instead.
So, if you come across this, click in the formula bar and press ctrl + shift + enter and it should sort the whole thing out.

Related

How to exclude 0 and blank cells when using excel MIN function

Got this formula:
{=IF(A4=MIN((C4=$C$4:$C$46711)*(B4=$B$4:$B$46711)*($A$4:$A$46711)),"First Event","All")}
I'm using the same one for MAX, and it works just fine. But when changing to MIN it fails, and I suppose it's because of value 0 and/or blank cells in my range. I've tried to add "ISNUMBER" after the "IF" but it doesn't do the trick...
How can this formua be modified to return lowest value, not counting 0 and/or blank cells in Column A?
If you have this function, you can use something like the below in place of your MIN function:
=MINIFS(A1:A10,A1:A10,"<>0")
If not, something like:
=MIN(IF(A1:A10<>0,A1:A10,""))
Depending on your version of Excel, you may need to "confirm" this array-formula it by holding down ctrl + shift while hitting enter. If you do this correctly, Excel will place braces {...} around the formula as observed in the formula bar.
Substituting in your formula would look like:
=IF(A4=MIN(IF(((C4=$C$4:$C$46711)*(B4=$B$4:$B$46711)*$A$4:$A$46711)<>0,(C4=$C$4:$C$46711)*(B4=$B$4:$B$46711)*$A$4:$A$46711,"")),"First Event","All")
I test your formula for a smaller range, there can be a smaller issue, which is causing trouble to you.
In your range $A$4:$A$46711 of the formula there can be a number or entry which is "text" formatted
I have done the following three trials:
Trial 1. Try it with blanks
Trial 2. Try it with blanks and zeros too.
Result: In both the cases your formula, is working fine
Trial 3: with Text in column A, It is generating an error
Hence I am concluding to check your A column range for any text formatting
Remember you can also use Aggregate for these since Excel 2010:
=AGGREGATE(15,6,A1:A10/((A1:A10>0)*(B1:B10="a")),1)

How to simplify multiple COUNTIFS in excel with non-consecutive ranges

I have a spreadsheet...
A you can see, the cell F2 has a formula with multiple COUNTSIF, basicly checks the cells F14, F33, F62 y there is a Pass there, and if there is one will give you a % completion. My question is that I have to add around 20-30 COUNTIFS to that formula, is there a way to simplify it.
=(COUNTIF(F14,"Pass")+COUNTIF(F33,"Pass")+COUNTIF(F62,"Pass")+COUNTIF(F75,"Pass")+COUNTIF(F88,"Pass")+COUNTIF(F105,"Pass"))/(COUNTIFS(F14,"<>na")+COUNTIFS(F33,"<>na")+COUNTIFS(F62,"<>na")++COUNTIFS(F75,"<>na")++COUNTIFS(F88,"<>na")+COUNTIFS(F105,"<>na"))
This is not the final formula, still missing around 20 entries. If you're wondering why not do a simple F15:FXX, because i just need the cells that have a test case name, like F14, F33, etc.
For the first part of your formula, you can use the INDEX function to return a non-contiguous set of values, which you can test.
For example, the equivalent for the first part would be:
=SUM(N(INDEX($F:$F,IF(1,N({14,33,62,75,88,105})))="Pass"))
The IF(1,N({…})) part is how you specify which cells (rows) in Column F to return.
Without knowing more about your data, not sure about handling the percentage issue.
Your posted formula would not calculate a percentage, as it is only dividing the SUM by whether or not F14<>"na" is true, and then adding one for the <>"na" factor for the rest
In earlier versions of Excel, you may need to confirm this array formula, hold down ctrl + shift while hitting enter. If you do this correctly, Excel will place braces {...} around the formula seen in the formula bar.
If you want to return the percent "pass" in your list of cells, merely divide the SUM by the number of cells. You can either hard-code that number, or compute it with something like:
COLUMNS({14,33,62,75,88,105})
Or all together:
=SUM(N(INDEX($F:$F,IF(1,N({14,33,62,75,88,105})))="Pass"))/6
or
=SUM(N(INDEX($F:$F,IF(1,N({14,33,62,75,88,105})))="Pass"))/COLUMNS({14,33,62,75,88,105})

Excel formula to count multiple possible combinations in single cell

Newbie-ish with Excel here. I'm trying to keep things simple for long term ease of use since most at my job don't know much of anything with Excel or anything with VBA.
I'm looking to have a formula count cells containing up to 4 different codes (TRM2-TRM5) out of 32 possible codes. However, the cell these combinations are entered in is not required to be in any specific order.
Such as:
B1 (TRM2, R2, TRM3)
B2 (TRM2, PN1, DC5, TRM4)
B3 (PN1, IPA5c, HW2, TRM5)
B4 (PN1, HW2, R2)
The desired result of the formula is a count of 3
I don't need to count the individual number of times the TRM codes appear. Just the number of cells they appear in a range (such as B1:B99).
I've tried COUNTIFS but quickly discovered I'd have to have a COUNTIFS for each possible combination of the 4 codes.
So far the simplest way is to use multiple instances of conditional formatting that highlights the cells that contain one of the four codes and do a visual count. All the examples I've read don't have multiple values in one cell so I'm not sure how to tackle it.
For those that are curious, the purpose is error reporting for issues missed in an audit.
Thanks for the help!
Given your example, you can do this with a helper column.
Either hard code an array constant with the codes to find, or enter them in separate cells someplace. I did the latter and named that range theCodes.
Use this array formula in the helper column:
C1: =MIN(FIND(theCodes,B1&CONCAT(theCodes)))<LEN(B1)
and fill down as far as needed
This will return TRUE or FALSE depending on whether any of the codes are present in the cell.
Then, a simple COUNTIF will count all the TRUE's
D1: =COUNTIF($C:$C,TRUE)
NOTE: To enter/confirm an array formula, hold down ctrl + shift while hitting enter. If you do this correctly, Excel will place braces {...} around the formula seen in the formula bar.

Excel Formula To Count The Number Of Times a Text Appeared in a Cell

I am looking for an Excel formula using IF function to Count the Number of Times a specific text appeared in a range of cells.
I do not want the COUNTIF formula. I want the formula to be built using IF function.
Any suggestion guys!! I would be really grateful.
Check how many times "f" appears in cell F7:
=LEN(F7)-LEN(SUBSTITUTE(F7,"f",""))
Or something like this if you really must use IF statement:
This will show you the number of "AA" occurrences in a range B2:G2 - look at the picture
{=SUM(IF(B2:G2="AA",1,0))}
Please remember that this is an array formula, so to execute it you'll need to use Ctrl+Shift+Enter
excel example

Data generation in Excel

Good morning, I am new at using excel and I'll be very thankful if someone can help (and I'm sure that the answer is easy from your point of view).
https://img15.hostingpics.net/pics/785039data.png
The screen capture reprents a simplified way of explaining what I am looking for:
For each number in the first column (which can appear more than once), I want to generate a corresponding Id (See column Id to affect which is the type of data).
We are only looking at the beginning of "Number", which can be up to 8 number is size.
Sometimes there can be tricky case, as te example starting with 40 vs 402 which are not affected to the same Id.
As I am new on excel maybe this answer or question exist but I don't know how to search/name it.
Thank you for your help, have a great day.
Tricky formula. Not exactly the prettiest thing ever but this formula works: (Line breaks added for readability)
= IFERROR(INDEX(D$2:D$7,MATCH(MAX((((A2-(C$2:C$7*10^(CEILING(LOG10(A2+1),1)
-CEILING(LOG10(C$2:C$7+1),1))))=MOD(A2,10^(CEILING(LOG10(A2+1),1)
-CEILING(LOG10(C$2:C$7+1),1))))+0)*C$2:C$7),C$2:C$7,0)),"(no match)")
A few things to note:
You didn't include cell ranges so you will have to manually change the cell ranges in the formula above to whatever your particular cell ranges are.
This is an array formula, meaning after you enter this formula into a cell, you must press on the keyboard Ctrl+Shift+Enter rather than just Enter.
The formula looks for the "strongest" match. For example, if a number is 40200000, the formula would return "Grapefruit" because it is a stronger match than "Grape".
If no match is found, I just have the formula return "(no match)" but you can obviously change that to whatever you want.
I assume this won't be an issue, but the formula will not work if any negative numbers are used.
See below, screenshot that shows formula works for your data.
You can try this array formula (click Ctrl + Shift + Enter together) from cell B2 and drag it down:
=IFERROR(INDEX(D$2:D$7,MATCH(MAX((VALUE(LEFT(A2,LEN($C$2:$C$7)))=$C$2:$C$7)*C$2:C$7),C$2:C$7,0)),"")
This will try to match the longest number (with MAX) and return the value (with INDEX/MATCH).

Resources