I would like to know how to specify a cell in a sum function based on a variable.
For instance,
startpoint: a1 = 5
length: a2 = 10
i have data in b1 - b100.
I want a sum function sum(b(a1):b(a1+a2))
which would yield:
sum(b5:b15)
Thank you
Use the non volatile INDEX function:
=SUM(INDEX(B:B,A1):INDEX(B:B,A1+A2))
Related
The follow Formula give me the correct Value:
=SUM(SUMIFS('POS Data'!$G:$G,'POS Data'!$B:$B,{"5","10","11"}))
However I require part of the criteria to be taken from a cell value. eg
=SUM(SUMIFS('POS Data'!$G:$G,'POS Data'!$B:$B,E1))
E1 cell value = {"5","10","11"}
However the formula gives a 0 value. What am I missing? Why is it not recognizing that E1 is that value?
The solution used was as follows:
=SUMPRODUCT(SUMIFS('POS Data'!$G:$G,'POS Data'!$B:$B,E1:G1))
E1 = 5
F1 = 10
G1 = 11
That you #scottCraner
Assuming your import cell with your array is in E1, You have to change it from {"5","10","11"} to 5,10,11 in the cell value
=SUM(SUMIFS(G:G,B:B,TRANSPOSE(FILTERXML("<x><y>"&SUBSTITUTE(E1,",","</y><y>")&"</y></x>","//y"))))
Guys I am trying to write a dynamic sum formula where the array range starts from a cut-off date ( this date changes every month ).
I have the periods in the top first row 201801 in A2, 201802 in B2 etc.
and starting from A3 I have the sales' figures.
e.g. the cut-off date is 201806, so I need my sum formula to be =sum($F3:L3)
what I was trying to do is =sum(ADDRESS(3,MATCH($B$1,$A$2:$L$2,0),3):L3)
ADDRESS(3,MATCH($B$1,$A$2:$L$2,0),3) returns $F3 which does not work in the sum formula!
INDIRECT is volatile so may not be the best function to use.
I take it that L3 is static, and you're looking to sum from the lookup value to L3.
MATCH(201806,$2:$2,0) will return the column number that 201806 first appears in.
INDEX($3:$3,,6):$L$3 will return a reference to F$3:$L$3 (F being the sixth column - replace 6 with the MATCH function).
SUM(F$3:$L$3) adds it all up. Replace F$3:$L$3 with the INDEX.
The final formula would be:
=SUM(INDEX($3:$3,,MATCH(201806,$2:$2,0)):$L$3)
Replace 201806 with a range reference.
If the end date is variable you can use another INDEX function to find it.
This finds the last date using the MAX function:
=SUM(INDEX($3:$3,,MATCH(201806,$2:$2,0)):INDEX($3:$3,,MATCH(MAX($2:$2),$2:$2,0)))
This adds from June to December:
=SUM(INDEX($3:$3,,MATCH(201806,$2:$2,0)):INDEX($3:$3,,MATCH(201812,$2:$2,0)))
Suppose I've created these named ranges: Apples = "A1:A3", Pears = "B1:B3"
Then putting the formula "=Apples + Pears" in cell C3 is the same as "=A3 + B3"
Is there some way to specify an offset in the "=Apples + Pears" formula so that cell C3 refers to "=A3 + B2" instead?
In other words, how would an offset for "Pears" be specified so that it refers to B2 instead of B3?
Thanks in advance for any help!
Edit: I would like the formula to be relative, so that if I copied it to cell C2 it would refer to "=A3 + B1"
You can use the ROW() function of the current cell to get an index that is automatically updated when you copy the formula. This formula goes into C3, then when you drag it up, it automatically adjusts the index for Pears.
=INDEX(Apples,3,1)+INDEX(Pears,ROW(C3)-1,1)
Note that if your real data doesn't start in row 2, you'll need to subtract the additional amount from the row function to allow for the additional rows.
Use the INDEX function to specify a cell within a range, named or conventional.
=index(apples, 3, 1) + index(pears, 2, 1)
The OFFSET function will do the trick to move from cell B3 one cell up:
For numbers use the following function (e.g. number 3):
=A3+OFFSET(INDIRECT(ADDRESS(MATCH(3,B:B,0),2)),-1,0)
And for strings use this function:
=A3&OFFSET(INDIRECT(ADDRESS(MATCH("Pears",B:B,0),2)),-1,0)
In excel, say I am trying to find average of 5 cells, I can put a formula
=Average(C1:C5)
I would like to modify the formula such that
= Average(C1:CXXXX)
where XXXX comes from another cell.
Is there a way to achieve this?
You probably want to have a look at the INDIRECT function if you need it as a fomula in a cell - you can use it like this, assuming that D1 contains the row that you call XXXX in your question:
=AVERAGE(INDIRECT("C1:C"&D1))
If this is in vba, then you can use:
= Average(Range(Range("C1"),Range("C") & XXXX))
where XXXX is the row number, assuming that Average is a function that you have defined somewhere.
Use the INDIRECT function. Indirect returns the reference by a string. INDIRECT("A1") returns the cell A1.
Your values are in the C column. Let's say that the XXXX is in cell D1. The formula becomes
=AVERAGE(C1:INDIRECT("C" & D1)).
I have two excel sheets. The first contains a formula for calculation with one input cell (A1), and one output cell (B1). The formula for B1 could be B1 = A1 * 3 (example).
The second sheet contains various values in column A: A1 = 4; A2 = 9; A3 = 5 ... In corresponding column B of this sheet I'd like to get the result of B1 (first sheet) = A1 (second sheet) * 3 for each A (second sheet) input value.
Basically I'd like to treat the first sheet as a function, where A1 is the argument and B1 the result that is passed back to the second sheet's B column.
Sheet 2
A1 4 B1 12 (result from sheet 1)
A2 9 B2 27 (result from sheet 1)
...
Is it possible without macros?
This is built into Excel. In version 2003, use the Data, Table menu.
You can find many examples on the net. Here is one.
You can create such tables with either 1 or 2 entries (parameters).
I don't think so .....
If in B1 Sheet1 you have
3*A1
If you try this in Sheet2 B1
`=SUBSTITUTE(Sheet1!$B$1,"A1",A1)`
it will give
3*4, and Sheet2 B2 will be
3*9etc
But I don't see how you could coerce this to a numberic calculation with formulae without possibly some heavy duty formula string parsing to separate numbers from operators (which is unlikley to flex as desired if you change the entry in B1 Sheet 1)
[Update 2: but fwiw I have done it with a named range]
I used this range name
RngTest
=EVALUATE(3*INDIRECT("rc[-1]",FALSE))
This is a global range name so it will work on any sheet, more powerful than my prior OFFSET effort. It multiplies the cell to the immediate left by 3
so entering =RngTest in B1:B3 (and then in this new example C1:C3 as well)
gives the output you want
I think you want to use this in your sheet two column.
Sheet1!B1 * Sheet2!A1
Entirely without VBA: expect lots of pain, I won't go there. But...
To substantially reduce the amount of pain, you could actually use this one tiny VBA user-defined function (not technically a "macro"), basically just a wrapper to make VBA's Evaluate function available in worksheet formulas:
Function eval(myFormula As String)
eval = Application.Evaluate(myFormula)
End Function
You could then use it like this in cell B1 on sheet 2:
=eval(SUBSTITUTE(Sheet1!$B$1,"A1","A"&ROW()))
Note that this requires Sheet 1 cell B1 to contain A1*3 and not =A1*3, i.e. no equal sign. Maybe with a bit more fiddling around, it can be made to work even with the = sign there...
EDIT: Actually, if you format Sheet 1 cell B1 as Text before typing in the formula, this will work even if your formula starts with a =.
Is it possible without macros?
Yes!
You can now use =LAMBDA for this.
Define your function using the name manager, then reference it in your second sheet's formula.
See syntax at Introducing the LAMBDA function.
For more information about how to use the LAMBDA function, see the support documentation.