Counting Numbers within a cell - excel

Currently I am trying to figure out the number of purchases within one year. In my QTY purchased cell I have a list of quantities (800+2400+2400+2400+2400+2400+2400). This cell shows 7 different purchases.
My question is, what formula will take this cell and count the number of purchases individually and spit out 7 for the number of purchases, without me having to count them manually??
I have tried using both Len and Count formulas, however, they continue to either count the characters or just the cell itself.
Thanks!
Scott

You should probably structure your worksheet differently, as highlighted by Chris in the comments.
If you want to keep it that way, you can use a user-defined function in a VBA module to retrieve the formula text and then use that to count the number of "+" signs.
Public Function FormulaText(rng As Range)
FormulaText = rng.formula
End Function
A counting formula could be:
=len(formulatext(a1))-len(substitute(formulatext(a1),"+",""))+1

Related

Get Count of Cells used in Excel Formula

I want to get the count of cells used in an excel function.
For example say I have a sum function ='CV'!D11+Farmer!D11+'County'!D11+Rt!D11+WT!D11+'Country'!D11
I need a function that will tell me how many cells were used to get the total sum. In this case it is 6. The tricky part is if one of the cells used is blank I do not want it counted. For instance say cell D11 on the Farmer sheet is blank I do not want it counted in the total. So the total should be 5.
Use COUNT:
=COUNT('CV'!D11,Farmer!D11,'County'!D11,Rt!D11,WT!D11,'Country'!D11)
It will only count the cell if it has a number
You should really try to collate all your data in to a single sheet before running calculations. For the sake of example, I'll assume you have it in the range A1:A5, then you can add handling of the various cases using array formulas:
Get the count of non-empty cells (the ISBLANK function is untrustworthy in my experience): {SUM(IF(LEN(A1:A5)>0,1,0))}
Get the sum of those cells: SUM(A1:A5)
(must use Ctrl+Shift+Enter to enter the formula as an array formula, you will know it worked if the formula shows like {IF(...)} with the curly brackets)
Because blank/missing values are treated implicitly as 0 in the SUM function, this case is simple. If you have other validations then you'd have to write an array formula for the summation as well. For example, only including numbers between a min and max threshold (e.g. if you want to exclude outliers):
{SUM(IF(AND(A1:A5 >= yourMinValue, A1:A5 < yourMaxValue), A1:A5, 0)}.
If I understand your question correctly, you want to literately count the number of cells used in a formula which in your example is summing 6 values from 6 different locations.
I used the following example to demonstrate my solution:
The sum of =A1+B1+C1+D1+E1+F1 is 10 where cell C1 has a 0 value in it but cell E1 is blank.
Using the following array formula I was able to count the number of cells that have a value other than 0:
=SUMPRODUCT(IFERROR(ABS(N(INDIRECT(TRIM(MID(SUBSTITUTE(RIGHT(FORMULATEXT(A3),LEN(FORMULATEXT(A3))-1),"+",REPT(" ",100)),100*ROW(INDIRECT("1:"&LEN(FORMULATEXT(A3))))-99,100)))))>0,0)*1)
Please note you MUST press Ctrl+Shift+Enter upon finishing the formula in the formula bar otherwise they will not function correctly.
The logic is to use a combination of TRIM+MID+SUBSTITUTE+RIGHT+FORMULATEXT+REPT+ROW+INDIRECT to extract the cell addresses from the original formula, then use INDIRECT to convert the cell address into the values stored in those cells, then use a combination of IFERROR+ABS+N to find out if any of these values are not 0, and lastly use SUMPRODUCT to add up all the TRUE results.
It is obvious that there are a couple limitations of my solution:
If your actual formula is not strictly in the form of A+B+C+D+E+F, then my SUBSTITUTE part of formula will need further modification;
The formula will treat cells containing 0 as blank and does not include them in the count.
Let me know if you have any questions. Cheers :)

Is there a general way to process only visible cells in excel?

I am wondering, if there is a general way to express, that only visible rows of a formula should be taken into account.
If I have for example a formula sumif($E5:$E100; "ABC"; $F5:F100) it would be very helpful, if there would be a way to express, that the given ranges should only take visible cells into account. I could imagine that a kind of prefix can be specified to a range construct like % or that like. For example the formula then would look like sumif(%$E5:%$E100; "ABC"; %F5:%F100) to make clear, that in the given ranges only visible rows should be taken into account.
Same would then for example be for sum(%A1:%A100) which would mean, that in the range between A1 and A100 only visible cells should be taken to sum up the cells.
The point is, that this construct could be taken inside any kind of formula, no matter what it is.
Thanks in advance
Georg
Generically to sum sumrange based on a match in criteriarange.....but only for visible rows you can use this formula: =SUMPRODUCT((criteriarange=criteria)+0,SUBTOTAL(109,OFFSET(sumrange,ROW(sumrange)-MIN(ROW(sumrange)),0,1,1))) The first part (criteriarange=criteria)+0 just checks the criteria for each row and returns 1 for a match or 0 OFFSET returns an "array of ranges" with each range in this case being a single cell from the sum range. SUBTOTAL can process that and with the sum function (109) gives the "sum" (i.e. the value) of each cell, only when visible. – SUMPRODUCT then multiplies the two ranges and sums the result, effectively giving you the sum of visible rows where the criteria matches
Try This
=SUMPRODUCT(($E$5:$E$100="ABC")+0,SUBTOTAL(109,OFFSET($F$5:$F$100,ROW($F$5:$F$100)-MIN(ROW($F$5:$F$100)),0,1,1)))

Excel Average - Counting the number of variables

I'm using the average function excel to get the average of a series of hotel prices in various European cities.
=average(21,42,63,84,105)
I'd like to be able to count the number of variables in each average function (for example, in the above example there's 5). The data is scrubbed from websites which is why it's in the format above rather than placed into separate cells.
Is there a way to do this without taking out the variables, putting them into a cell and then separating out the cells using Text to Columns?
Thanks!
You can turn your equation into a string using FORMULATEXT() and then deduce the number of values being averaged by counting the instances of commas in your string (which relates to your final answer by Total Commas + 1 = Total Values
The first portion of the equation counts the character length with commas. The second portion counts the character length without commas. The difference is simply the number of commas present. We then add one since your last value is not followed by a comma
=LEN(FORMULATEXT(A1))-LEN(SUBSTITUTE(FORMULATEXT(A1),",",""))+1
Assumes your average formula is in cell A1
I am a fan of using UDFs, so here's an alternate method.
You can create a custom User Defined Function (UDF) for this. Just split the function by the deliminator and get your number from the UBOUND().
Public function getNumArgs(inputRng as range) as long
'First check that you are actually looking at a formula
If Left(inputRng.Formula, 1) <> "=" Then
getNumArgs = False
exit function
End If
getnumargs = ubound(split(inputrng.formula, ",")) + 1
end function
You will add 1 because VBA uses Base 0.
You will then use your custom UDF the same way you do any other worksheet formula:
=getNumArgs(A1)
The largest benefit of using a UDF is that you do not have to remember a complex formula.

How to count one cell value depending upon the occurrence of specific value in another cell range

I am working on an attendance sheet in Excel 2010. I need to count total no of attendance of a student in terms of his/her category.
For example, I have 4 student categories:
CAT1
CAT2
CAT3
CAT4
Please note that the sheet is not shorted on category, so their occurrence is random. Now I have 30-31 cells adjacent to these categories for attendance. These cells have values either a "P" or an "A".
Now I have to count total no of attendance in each category after the end of the month.
Please help !
EDIT: Kindly see the image:
EDIT: #Rosenheimer, As you can see in the image I uploaded, my cell range for attendance is not contiguous. Is there any way to refer to multiple cell ranges in SUMPRODUCT? Right now, I am using 1 SUMPRODUCT for each range and adding them which is very lengthy:
=SUMPRODUCT((Sheet1!E6:Sheet1!AI14=Sheet1!A65)(Sheet1!D6:Sheet1!D14=Sheet1!A69)(Sheet1!C6:Sheet1!C14=Sheet1!A67))+SUMPRODUCT((Sheet1!E18:Sheet1!AI26=Sheet1!A65)(Sheet1!D18:Sheet1!D26=Sheet1!A69)(Sheet1!C18:Sheet1!C26=Sheet1!A67))+SUMPRODUCT((Sheet1!E30:Sheet1!AI37=Sheet1!A65)(Sheet1!D30:Sheet1!D37=Sheet1!A69)(Sheet1!C30:Sheet1!C37=Sheet1!A67))+SUMPRODUCT((Sheet1!E41:Sheet1!AI45=Sheet1!A65)(Sheet1!D41:Sheet1!D45=Sheet1!A69)(Sheet1!C41:Sheet1!C45=Sheet1!A67))+SUMPRODUCT((Sheet1!E49:Sheet1!AI62=Sheet1!A65)(Sheet1!D49:Sheet1!D62=Sheet1!A69)(Sheet1!C49:Sheet1!C62=Sheet1!A67))
Thank you !
You could do it with a conditional sum:
Please note that it is called SUMPRODUCT in English Excel applications (function names are translated for Microsoft Excel).
The evaluation A$2:A$7=D2 is either true or false, which will be interpreted as 0 (false) or 1 (true) for the multiplication with the literal 1.
Now you can add further statements to the evaluation, for example you might extend it to (A$2:A$7=D2)*(C$2:C$7="P")*(F$2:F$7>=DATE(2015,07,01))*(F$2:F$7<DATE(2015,08,01)) to only count students that are marked with P in July.
Edit:
Since you're effectively using a matrix and not just a list, you need to use a sligthly different variation, but it can still be done with SUMPRODUCT, look at this example:
If you want to count the occurrence of different cells that meet a specific criteria then use the function "COUNTIF". But if you want to count cells that fulfill multiple criteria then use the function "COUNTIFS"

Formula to Add 1 to current cell if certain text is picked detected in a range of cells

I am currently making a spreadsheet which has information relating to properties, One of the columns lists the source for the property such as Zoopla, Rightmove, Fish4. I need a formula that will scan the entire Sources Column for 1 word and add a value to a cell that shows the total number of Sourced information from that source. I have been trying for sometime and cannot figure out the formula.
Rightmove Total = 3
Zoopla Total = 4
Any information is appreciated
try this:
=SUM(IF((A1:A5="Saint"),1,0))
if the searched string is found, assign 1 to each true condition. then add up the results and there you go!
Note: please change the column numbers and search string, as this is just an example
If I'm understanding your problem properly, what you need is the COUNTIF() function.
=COUNTIF(Sheet1!A:A, Sheet2!A2)
Will count the number of occurrences of the value within cell A2 of Sheet2, into column A:A of Sheet1.
So, if Sheet2!A2 has Rightmove and Rightmove appears three times in Sheet1!A:A, then the formula will return 3.

Resources