How do I count the number of populated cells (with text/number or combinations of text+number)?
I tried =countif(A2:A2000,1=1) (with a general criteria, e.g. 1=1 always) but shows zero (0) for a text column.
I think for the answer above, it should rather be
Application.WorksheetFunction.CountA(Range("A2:A2000"))
I have always faced problems while not mentioning Range, cause it considers the whole range to be as a single unit.
The formula is =COUNTA(A2:A2000) : non-blank cells are counted.
In VBA it's WorksheetFunction.CountA("A2:A2000")
Dim Coloumncount As Integer
Coloumncount = Application.WorksheetFunction.CountA([D1:D100])'count how many filled cell in coloumn "D"
Related
I have a range/list with values per row. Some of the rows are blank.
I want to name the range, and the range should reach the last value (nonblank cell).
So if any cells below the range that become populated, then the range must expand to those cells, even if there are blanks between, like in scenario 2.
Do anyone have a suggestion to how to solve this?
Try below formula which work both for number and text strings.
=Sheet1!A2:INDEX(Sheet1!A:A,MAX(IF(Sheet1!A:A<>"",ROW(Sheet1!A:A),0)))
If you are on Excel-365 then try-
=Sheet1!A2:INDEX(Sheet1!A:A,MAX(FILTER(ROW(Sheet1!A:A),Sheet1!A:A<>"")))
If the non-blank entries in that column are numeric, you can use:
$M$5:INDEX($M:$M,MATCH(88^88,$M:$M))
where 88^88 is assumed to be larger than any numeric within the range.
If the non-blank entries in that column are non-numeric, and none of the blank entries are in fact null strings (""), you can use:
$M$5:INDEX($M:$M,MATCH("Ω",$M:$M))
I am trying count the number of unique names in column B on a worksheet. The worksheet that column B is located, copies the values from other worksheets in the same workbook. If there is a blank cell on the previous worksheet it shows as a zero on the worksheet where the formula is located. Names show as names. I am currently using {=SUM(1/COUNTIF(B1:B468,B1:B468))}. However I am not certain that is the correct formula. I am trying to count only unique names and exclude both the blanks & the zeroes. I have checked both similar questions proposed here & on Google. What I found was that they counted uniques with blanks, but not with blanks & zeroes.
By "counting uniques" I assume you don't want to count the same value twice.....in which case try this formula
=SUMPRODUCT((B1:B468<>0)/COUNTIF(B1:B468,B1:B468&""))
Barry Houdini's solution works, but I think this would be considerably more efficient (though that's not an issue if you only have ~500 records):
=SUM(IF(FREQUENCY(IF(B1:B468<>0,MATCH(B1:B468,B1:B468,0)),ROW(B1:B468)),1))
Entered as an array formula by typing Ctrl+Shift+Enter.
Also, regarding ImaginaryHuman072889's answer, the NOT(ISBLANK) test is redundant. This would do the exact same thing (albeit, as Barry Houdini pointed out, wouldn't account for unique values)
= SUMPRODUCT(--(B1:B468<>0))
I would do this:
= SUMPRODUCT((B1:B468<>0)*NOT(ISBLANK(B1:B468)))
This counts all entries in the cell range that are non-blank and non-zero.
The question is slightly confusing, so I will do my best to elaborate. I have a series of cells in a row with all of the cells in the row with a value of 0 and one cell having a value of 1. I want to use the COUNT function to count all of the cells to the right of the cell that contains the value of 1, including that cell. I would then use this number of counted cells in another equation. Does anyone have any suggestions on how to do this? I have tried using a lookup function inside of the count function, but it has not worked. This is my closest guess:
=COUNT(Lookup(1,A1:J1):J1)
This results in an error. Do I need to use VBA to make this work or should I be able to write an equation? I appreciate the help, or if there are any other strategies that I can use to attain the result I am looking for.
Edit: I am adding in some sample data and expected results. I am trying to count all of the cells to the right of the "1" including the cell containing the "1". So in this example, I would expect the formula to return "13" as there are 12 cells to the right of the "1"
You can use OFFSET() and MATCH():
That last "50" is a bit of a guess since I'm not sure how far to the right you want to count...
...and re-reading your question it's not clear if you only want to count values of 1 or if you also need to count other values as long as they're to the right of the first 1.
With data in A1 through J1, consider:
=10-MATCH(1,A1:J1,0)+1
In this case. 4 is the number of cells from G1 through J1, inclusive.
Assuming your range of 0 and 1 values is in row 2, starting from column B, use this formula in B3 and copy it across for as far as you need:
=IFERROR(COUNT($B2:B2)+1-MATCH(1,$B2:B2,0),0)
You could also use a formula of
=IF(A3>0,1+A3,IF(B2=1,1,0))
but that could cause issues if you have something in cell A3 itself.
You can use this formula:
=COUNTA(INDEX($A$1:$J$1,1,MATCH(1,$A$1:$J$1,0)):INDEX($A$1:$J$1,1,10))
The benefit to use this is it is not a volatile function, and it will also work for 1 appears in the last column.
You can use "COUNTIF" formula to count number of occurrences of specific number in a range of cells.
To count no of occurrences in a row.
=COUNTIF(1:1,1)
If it is in a column then
=COUNTIF(A:A,1)
Hope you are looking for a countif function.
COUNTIF(A1:A10, 1)
The above function counts the cell that has value 1 within the range A1:A10
I have a excel formula as below,
COUNTIFS($A$8:$A$14,$A8,$B$8:$B$14,$B8)
Here I want the criteria range to be calculated with a simple logic.
Instead of $A$14 I want this value to be calculated A$8+4 i.e. $A$14
In other words, it should get the current row and add 4 to be the criteria range for COUNTIFS
How can this be done is excel within the COUNTIFS formula?
Cheers
You could use =OFFSET(Cell Reference, Rows, Columns) within your formula to achieve this, for example:
=COUNTIFS($A$8:OFFSET($A$8,6,0),$A8, etc...)
Lets assume that the size of your range to be returned is stored in the cell D1.
=COUNTIFS($A$8:INDEX(A:A,ROW($A$8)+D1),$A8,$B$8:INDEX(B:B,ROW($B$8)+D1),$B8)
If you want the range to be defined as a certain number of rows after the current row as stated in your question, then still assuming the number of rows to be added is in D1, you would use the following:
=COUNTIFS($A$8:INDEX(A:A,ROW()+D1),$A8,$B$8:INDEX(B:B,ROW()+D1),$B8)
Expanding on Oliver's answer. The full format of OFFSET allows you to specify a whole range, not just one cell. OFFSET(Reference, Row Offset, Col Offset, Height, Width) so you could do:
OFFSET(A8,0,0,4,1)
This specifies the range A8:A11. In the COUNTIF
=COUNTIF(OFFSET(A8,0,0,4,1),A8,...)
Locking cells with $ works the same way within OFFSET if needed.
Try this:
=COUNTIFS(INDIRECT("$A$8:$A$" & 8+6),$A8,INDIRECT("$B$8:$B$" & 8+6),$B8)
I have a row with multiple blank values. I want the answer to be "" if all values are blank. If any of the cells contain a value, I would like to take the SUM of those cells, and add 10 to it. The formula I am using is below, and it always displays the answer as "10", even if all cells are blank. Please help.
=IF(ISBLANK(A1:D1),"",SUM(A1:D1)+10)
ISBLANK() only works on a single cell. You want to use COUNTA() instead.
Counts the number of cells in a range that are not empty
=IF(COUNTA(A1:D1) = 0,"",SUM(A1:D1)+10)