Excel Version: Microsoft 365 bundle (V 2106 Build: 14131.20278)
I'm trying to create an Excel formula that outputs a number onto a single cell (B11); the formula must:
I understand that it's not conventional to count inputted line breaks for a range; but that's what I need.
See the attached image:
RANGE = In this example, the range of (non-blank AND non-"N/A") cells I want to count go from B2 to B8.
Cell w/ Formula: B11
As of now, I only have the following formula done.
=SUM(LEN(B2:B8)-LEN(B2:B8;CHAR(10);""))+(LEN(B2:B8)>0))
This formula outputs == "9" (i.e., 9 line breaks: ignores blanks, but includes the string "N/A")
This formula allows me to count all line breaks present on that given range (so, it doesn't count blank/empty cells), but it obviously doesn't exclude the specific string "N/A".
Expected output == "8" (i.e., 8 line breaks: ignoring blank cells AND cells with the string "N/A")
I suppose this could be accomplished with an "IF", but I haven't figured it out yet.
Thank you for your time!
PS: I tried to make a table in here, but I was not able to add line breaks inside a single cell; so, I ended up resorting to an image to explain my point, sorry about the inconvenience!)
Here is an arrow formula can help you to count cells ignoring zeros and blank cells. Select a blank cell that you want to put the counting result, and type this formula =COUNT(IF(A1:E5<>0, A1:E5)) into it, press Shift + Ctrl + Enter key to get the result.
The COUNTIF not blank function counts non-blank cells within a range. The universal formula is “COUNTIF(range,”<>”&””)” or “COUNTIF(range,”<>”)”. This formula works with numbers, text, and date values. It also works with the logical operators like “<,” “>,” “=,” and so on.
Best practices. Be aware that COUNTIF ignores upper and lower case in text strings. Criteria aren't case sensitive. In other words, the string "apples" and the string "APPLES" will match the same cells.
Right, since you have got access to Microsoft 365, try the following:
=SUM(FILTER(1+(LEN(B2:B8)-LEN(SUBSTITUTE(B2:B8,CHAR(10),""))),LEN(B2:B8)*(B2:B8<>"N/A"),0))
Nicely layed out question btw, and a fun little issue to work on. Hopefully the above helped you out.
Just for a different approach:
(edited after @ScottCraner pointed out it didn't account for N/A)
=LET(x,FILTER($B$2:$B$8,B2:B8<>"N/A"),
y,TEXTJOIN(CHAR(10),TRUE,x),
z,SUBSTITUTE(y,CHAR(10),""),
LEN(y)-LEN(z)+1)
Of course, if you have a lot of data, TEXTJOIN
will fail if the resultant string is > 32,767 characters
Should be able to do this with a simple COUNTIF
(or COUNTIFS
if you want to add more criteria to count against).
Try =COUNTIF($B$2:$B$8, "<>N/A")
EDIT1: As pointed out by cybernetic.nomad, a better approach to dealing with non-numeric data will be COUNTA
. Another solution might be to just filter the whole data with something like:
=COUNTA(FILTER($B$2:$B$8, $B$2:$B$8<>"N/A"))
EDIT2: As pointed out by Scott Craner, this solution does not account for line breaks. You can add those in by using:
=COUNTA(FILTER($B$2:$B$8, $B$2:$B$8<>"N/A"))+
SUM(LEN($B$2:$B$8)-LEN(SUBSTITUTE($B$2:$B$8,CHAR(10),"")))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With