Count rows in a dynamic range - excel

Consider a very simple example of a dynamic range:
Cell C10 (arbitrary cell):
=FILTER(Table1[List1],NOT(ISNUMBER(XMATCH(Table1[List1],Table1[List2]))))
I would like to now know how many rows are in the dynamic range starting at C10. I tried simply:
=ROWS(C10)
but it returns '1' even when there are more than one rows returned. Is this possible?

Use COUNTA and the spilled range operator #:
In C10:
=FILTER(Table1[List1],NOT(ISNUMBER(XMATCH(Table1[List1],Table1[List2]))))
In D10:
=COUNTA(C10#)
Or like your original approach, you can use ROWS with the spilled range operator:
=ROWS(C10#)

Related

Sum a list of indirect ranges from a dynamic range

I have a list of ranges in a column. The ranges are part of a dynamic named range and are in text format.
$A$1:$A$5
$A$6:$A$10
$A$11:$A$15
...
The aim is to SUM the values between each range in the dynamic range as calling the dynamic range should iterate through all the ranges. However, does not with =SUM(INDIRECT(<dynamic_range>). This formula only returns one value which does not correspond with the first range in the dynamic range.
For example, return the sum of the first range, then in the next row, return the sum of the second range, so on and so forth until the end of the dynamic range.
I am trying to keep this preferably as a formula and not in VBA.
Use SUMIF not SUM with the dynamic array formula in Office 365 it will spill the sums:
=SUMIF(INDIRECT(rng),"<>")
Avoiding volatile INDIRECT you can use:
=SUM(INDEX($A:$A,SEQUENCE(5,,ROW()*5)-4)) when you have office365 or =SUM(INDEX(A:A,ROWS($1:1)*5-4):INDEX(A:A,ROWS($1:1)*5)) for older versions.
PS this is provided that the change of range is in same steps of 5 cells each time.

Use INDIRECT function on a Non Adjacent cell range

Okay, so I can very easily use Indirect on a cell that contains a range(entered as text) and then use INDIRECT to reference that range :
Like it's done here (see Answer):
Have one cell represent a cell range
*In the column C there's a drop down list for each '=INDIRECT()'
The range E2:E4 'returns' to the drop down list : Miami,Paris,Rome
The range E5,E2 SHOULD give: Amsterdam,Miami but it gives #REF
If you are putting each value in a separate column then you can use the following:
=IF(ISBLANK(A2),INDIRECT(B2),INDIRECT(A2)&","&INDIRECT(B2))
This will return your original indirect if the cell is blank and if not it will return both values. (I used column A but you can change the reference

How to grab the same range on multiple columns.

I'm working on a spreadsheet that does some pretty bizarre calculations... The long and the short of it is that I need to search the values in the 4 folowing ranges.
C5:C293, E5:E293, G5:G293 & I5:I293. The issue is that those ranges can change but will stay consistent across the columns. So For example instead of 5:293 it might change to 5:290. Is there an easy way to say "Look at the cells that are rows X:Y and are in columns A, B, C or D?"
google-spreadsheets
ARRAYFORMULA: Commas , arrange the array horizontally and semi colons; arrange the array vertically( stacking on top of each other)
=ARRAYFORMULA ({C5:C293,E5:E293,G5:G293,I5:I293})
QUERY: If there's a pattern in the columns, This will isolate the array:
=QUERY(TRANSPOSE(C5:I293),"Select * skipping 2",0)
In Excel, use the INDIRECT() function.
So, have a Start cell in A1, and an End cell in A2. Then your formulas to sum a range would reference the ranges for C column as:
=SUM(INDIRECT("C"&A1&":C"&B1))
And D column as:
=SUM(INDIRECT("D"&A1&":D"&B1))
Use range names rather than Indirect() or Offset() functions in the worksheet.
Create one range that covers the desired rows in the first column, e.g. "red" in the example, then create additional range names that offset the required columns from that range name.
How you construct your initial range is totally up to the circumstances, but the range names with Offset() will be super fast to deliver a result, whereas Indirect() and Offset() in worksheet cells can cause significant speed issues.
Use offset function, if you are in google-spreadsheets, use it dinamically:
=offset(C5,,,counta(C5:C),1)
will reproduce the range of a proper length.

excel formula for searching a range of cells in an another range of cells

Need a formula for searching a range of cells in an another range of cells.
Please find sample data in image :
Use MATCH function:
B1 =IF(ISNA(MATCH(A1,C$1:C$4,0)),"No","Yes")
Copy the formula down. You can adjust C$1:C$4 as needed.
From the example shown, I am assuming you need exact matches.
But if you want to return Yes, even if the cell is not an exact match as long as the string is found in the looked up array, you can use this:
B1 =IF(ISNA(MATCH("*"&A1&"*",C:C,0)),"No","Yes")

Calculate the COUNTIFS criteria range dynamically

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)

Resources