How to do a sum with variable (dynamic) range? - excel

I have a range B3:Bn with dates and a range C2:Y2 with another dates range. I am trying to find a date from a range B3:Bn in a range C2:Y2 and then starting from this cell to sum values. To do this i use:
=SUM(OFFSET(C3;0;MATCH(B3;$C$2:$Y$2;0)):Y3)
But instead of Y3 I would like to say: Sum values just starting from offset cell value till + 7 other columns.
Maybe someone can help with it?
Thanks!

In the table of the figure, cell B6 contains
=SUM(INDEX(A2:P2,1,B4):INDEX(A2:P2,1,B4+B5-1))
You may use an adapted formula to carry out your task.
It indirectly sets (with INDEX) the initial and final cells for carrying out the sum. I defined it as a starting cell (column 3 of range A2:P2) and a number of cells (4).
Points to consider:
You may need to use absolute referencing for some column/row references.
You may define your range to sum in slightly different ways.

You can use the INDIRECT function. It allows you dynamically create a cell range in a formula. So you could have one cell with a forumla that create your cell range as text e.g.
=B1&":"&B2 // in Cell C1, assuming B1 is "A1" and B2 is "A2" this would result in "A1:A2"
And then you can dynamically create a cell range from that using Indirect which you can then use function SUM on.
=SUM(INDIRECT(C1)) // would result the SUM(A1:A2) in our example

Related

Use cells to fill in the filepath for a SUMPRODUCT formula?

I am creating a SUMPRODUCT formula with a nested SIGN formula which helps to set criteria for which I want figures to be pulled from (similar to SUMIF or SUMIFS). Is there a way to have part of the formula refer to a cell/column that has a string, which is used to make up the filepath?
See below the example code.
=SUMPRODUCT(SIGN((
'S:\Folder\[File.xlsm]Range-97-98'!$B$5:$N$5
=
B$7
))*((
'S:\Folder\[File.xlsm]Range-97-98'!$B$423:$N$423
)))
The worksheet "Range-97-98' as you can see is a short Year range. This is because the current row the Sumproduct formula is on is a row assigned for 1997-98 (cell A9 = "1997-98")
Is there a way to change that Worksheet in the filepath based on the trimmed cell value from A column? eg. A10 is "1998-99" therefore the SUMPRODUCT would be Range-98-99'!..., and A11 is "1999-00" and so on.

Excel Define a range based on a cell value (column wise - A to E )

So, for example: My selection is A1:E1 That are five cells. is it possible to let excel determine this by setting a cell value (like A2) to 5.
It for the purpose of easily changes a lot of ranges with one change in a cell value. So if I would change the cell value (A2) to 6. The range would automatically change to A1:F6
Could somebody help me???
Try this formula
="=A1:"&ADDRESS(A2,A2,4)
Adding to my comment you can use INDEX to return the range you're after.
This will use B1 to determine the last cell in the range.
=$A$1:INDEX($1:$1,,$B$1)
This will then sum the values in that range:
=SUM($A$1:INDEX($1:$1,,$B$1))

indirect reference for sum a range

I want to have a sum formula in a cell such as =SUM(Ex:Ey) while E is the column and x and y are row numbers. Is there a way I can have excel to match x and y to the numbers in other cells? For example: cell D1=3 and D2=12 and there are many numbers in column E. By the end of column E, I want to have a cell that sum only the rows from the numbers of D1 to D2, which is sum of E3 to E12 in this example. The idea is that I can change D1 and D2 to change what rows in column I want to sum.
You can use INDIRECT to reference a range using a constructed string address - SUM(INDIRECT("E"&D1&":E"&D2)).
"E"&D1&":E"&D2 will give you the string "E3:E12" in your example, which INDIRECT will then convert to a reference to that actual range.
Note that INDIRECT comes with a recalculation overhead, but will be fine if you aren't doing too many of them or too complex things!
Another way to achieve this is to use the sumif formula or sumifs for multiple conditions. This works better in some situations and can be easier to read and audit\review.

In Excel, how to multiply ranges

In Excel, I want to know how to multiply one range of cells (say A1:F10) by another range of cells (static range say H1:M10) then put the answer in one cell only (say Cell P1) .... then move down one row and multiply the new range (say A2:F11) by the same static range (say H1:M10) then put the answer in the cell below the first answer (say P2) and so on....
When multiplying I need A1 to multiply by H1, B1 multiplied by I1, A2 multiplied by H2 and so on...
I have no clue, please thank you for your help... For info my range is a range of 2800 cells by 2800 cells so fairly large. Is there a way of doing this in Excel or do I need to use VB? thank you so much...
You can use Sumproduct for that. Use a relative reference for the first range and an absolute reference for the second range.
Consider the following screenshot:
The formula in cell P1 is
=SUMPRODUCT(A1:F10*$H$1:$M$10)
Copy down. In cell P2 it will change to
=SUMPRODUCT(A2:F11*$H$1:$M$10)
and so on, incrementing the rows of the first range in each row. The second range is fixed to H1 to M1 with the $ signs and will not change when copied down.

Excel 2007: how do I reference a non-consecutive named range?

I have 5 cells on the first row: A1 is 1, B1 is 2, C1 is 3, D1 is 4 and E1 is 5. Now I want to pick the odd numbers and name them "list_a_odd", so I hold CONTROL and select A1, C1 and E1, and type "list_a_odd" in the name box and hit ENTER. Now in A2, if I type "=SUM(list_a_odd)", it'll give me the result of 9, which is correct and expected. But if I type in "=list_a_odd", it gives me an error "#VALUE!".
However, if I select all 5 cells (A1 through E1) and name it "list_a", and I put "=list_a" in A2, it'll show "1" in the cell, and I can drag A2 to E2 to show all the 5 numbers in list_a. So that looks like only a problem when referencing non-consecutive named ranges in a cell. Is this an excel bug?
The list_a behaviour you describe is an example of the implicit intersection feature of ranges. list_a refers to a continuous range A1:E1, a formula expecting a single cell, when placed in the A to E column range using this range reference works out the intersection point and returns that cell.
That is, a formula in C2 =A1:E1 or =list_a_odd actually retuns a refence to just C1.
As you say, list_a_odd is a discontinuous multi area range. And implicit intersection doesn't apply to discontinuous ranges.
Some (but not all) functions work with discontinuous ranges, including SUM, that's why =SUM(list_a_odd) works as expected, just as =SUM(A1,C1,E1) works too.
EDIT
To return a continuous range that represents a discontinuous range I would use a user defined function combined with an array formula.
In the UDF use the Range.Areas property to loop through each of the sub ranges in a discontinuous range (remember that each item in Areas can be a single cell or a range in its own right). Build up an array of values to return to the array formula on the sheet.
The exact details will depend on your specific requirements and how generalised you want to make the UDF. Have a go, and post again if you need more help

Resources