indirect reference for sum a range - excel

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.

Related

Sum and subtract among column and row cells in excel

I have an excel document where I have some amount in number in different cells. For example, I have number in column H,I,J of row 1.
How can I sum H+I and then subtract J from the result of H+I?
Thanks
Hi and welcome to Stack Overflow.
Let's say you have your original value in cell H1, the value to add in cell I1, and the value to subtract from their sum in cell J1.
The formula would be:
=H1+I1-J1
Notes:
Since addition and subtraction are related functions, there is no need to add parentheses to enforce proper order of operations.
Addition operator and subtraction operator signs work, no need for explicit Excel functions. There is no subtract function in Excel (perhaps where your confusion comes from), so if you wanted to use explicit functions you would write
=SUM(H1,I1,J1*-1)
If you're trying to sum over a larger range (entire columns of I and J, for example), let me know and I'll adapt my response.
If you want to add two columns say H1+I1 and subtract J1 from the result(H1+I1) and store the final result into column K1, then first select the K1 column and in the formula section type =H1+I1-J1. In the picture below, I am adding value of A1 and B1. After that subtracting the value of C1 from A1+B1. So, for the cell D1 to show the result of A1+B1-C1, select D1 and write the formula as it is showing in the picture.

use dynamic range in countif formula

I have this sheet with data:
the search range (row 3) is filled until column AM and the count range (row 4 and lower) is only filled until column R (more columns will be filled in time)
I need to have a formula to use in my count if formula to find the last filled column.
So in this case the the search range for the countif formula has to be:
=countif(C3:R3;C4:R4)
but when column S is filled, the formula should automatically use column S instead of R. etc.
the formula is used to calculate an average of the scores/percentage for a certain skill (e.g. optellen+aftrekken, tafels, tijd). So just counting the arguments in row 4 or lower is not enough. It also has to count how many times the given skill is found in the applying range (Column C to R, C to S etc).
I have a combinated formula to have the complete first parameter for the countif formula:
="'invoer optie2 (2)'!C$3:"&(ADRES(3;AANTALARG('invoer optie2 (2)'!4:4)+1;2;1))
(the formula is in dutch).
the result is this:
'invoer optie2 (2)'!C$3:R$3
This is the part I need for my countif formula. I keep struggling on how to use this in the countif formula so it uses it a the search range.
How can I convert this "string" to the range in the countif formula?
Do not use ADDRESS and INDIRECT as they are Volatile.
Instead use INDEX:
=COUNTIFS('invoer optie2 (2)'!C$3:INDEX('invoer optie2 (2)'!$3:$3,MATCH(1E+99,'invoer optie2 (2)'!4:4)),"WhatYouWant")

How to simplify the formula for sums with one variable in Excel

I need to sum the result of a formula, repeated several times, which has a single value that changes from 1 to 180.The final formula must be contained in a single cell.
Column A contains values ​​from 1 to 180 (to simplify in the example I have only put 13).
Cell B1 contains a value expressed as a percentage.
Column C (C1 to C13) contains the following formula (cell C1 in the example):
=+((1/(1+(A1*1/12*$B$1)))).
Cell C14 contains the sum of all results.
By defining X the variable value of column A, the formula is in practice the following:
Column A will be not present in my sheet, so therefore I cannot refer my formula to the contents of any cell.
My need is to have only two cells in my sheet: B1, with the rate value; and C1, with the sum of the products with X from 1 to 180. That is what is contained in cell C14.
Thanks for your help and for your patience with my bad English.
This can be done using SUMPRODUCT:
=SUMPRODUCT(1/(1+(A1:A13*1/12*$B$1)))
You can use the SEQUENCE() function for your problem to replace the column A in your example.
More specifically, you can write the formula:
=1/(1+SEQUENCE(180)/12*B1)
which will automatically create an array with a length of 180 cells returning your desired series of values.
If you don't want to 'print' out that series at all but only show the sum right away, simply enclose the formula with the SUM() function:
=SUM(1/(1+SEQUENCE(180)/12*B1))

Excel: SUMIF refered to dynamic range

I need to write a SUMIF formula with reference to dynamic columns.
Here an example.
In the cell G7, I need to have the sum of the number related to Mark (row 3) from the column stored in the cell D3 (in this case H) to the column stored in the cell D4 (in this case L). The result of this formula gives the number 7 in cell G7 and the number 8 in G8.
I would like to manage this issue without using VBA if possible.
I thought at something like:
G7 = =SUMIF(F:F;F7;<the value stored in D3>:<the value stored in D4>)
I hope to have explained the issue well.
A simple sum with two INDEX/MATCH will do it:
=SUM(INDEX($1:$10000,MATCH(F7,F:F,0),CODE(UPPER($D$3))-64):INDEX($1:$4,MATCH(F7,F:F,0),CODE(UPPER($D$4))-64))
On note, this will only work till column Z, if you data is past that we will need to find something different than the CODE(UPPER($D$3))-64 to denote the column extents.
We would need to use INDIRECT, which if can be avoided, should. It should be avoided because it is volatile. So if your data goes past column Z then use:
=SUM(INDEX(INDIRECT($D$3&":"&$D$3),MATCH(F7,F:F,0)):INDEX(INDIRECT($D$4&":"&$D$4),MATCH(F7,F:F,0)))

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

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

Resources