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.
Related
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#)
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
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.
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)
when using the sumif function how do you get the [sum_range] to only add the positive numbers?
so if the function is =sumif(A:H,C34,H:H) how do I only add the positive numbers in column H
In your posted formula =sumif(A:H,C34,H:H) because the test range is A:H , the range that is summed is actually H:O (the shape of A:H = 8 columns starting at top left cellof H:H) Not sure if this is what you intended. Given the overlap in the criterai and sum ranges I suspect not. BTW this means cell J34 will always be included in the sum
SUMIFS is only available in Exel 2007 and later and would work for =SUMIFS(H:H, A:A, C34, H:H, ">0")
Unlike the range and criteria arguments in the SUMIF function, in the SUMIFS function, each criteria_range argument must contain the same number of rows and columns as the sum_range argument.
If you are using Excel 2003 or earlier, or if the range behviour described above is required, you can use somthing like,
=SUM(H:H*(A:A=$C$34)*(H:H>0))
or
=SUM(H:O*(A:H=$C$34)*(H:O>0)) ' this one won't work as is, you will have to resolve the overlapping ranges
entered as an array formula (Ctrl-Shift-Enter)
You can use the SUMIFS function:
=SUMIFS(H:H, A:H, C34, H:H, ">0")
The sum_range is at the beginning in this case, instead of the end in this case