I want to use a specific range reference programmatically to sum (next 25 cells), for which I'm using OFFSET(), which requires a cell reference. However, most lookup functions return indexes, or values, not cell references, so I have to use INDEX().
I find it a bit ridiculous that I have to do this just to find the cell reference of a cell programatically:
INDEX(A:A, MATCH(C2, A:A, 0), 1)
Is there a better way to get a cell reference programmatically?
The whole thing looks like:
=SUM(OFFSET(INDEX(A:A, MATCH(C2, A:A, 0), 1), 0, 1, 25, 1))
You will want to utilize multiple Match() and their offsets... see:
=SUM(OFFSET(A1,MATCH(C2,A:A,0)-1,0):OFFSET(A1,MATCH(C2,A:A,0)+24,0))
Broken down:
First cell in your range to sum in column 1 (A), have to subtract 1 from it so you're using your actual match reference:
OFFSET(A1,MATCH(C2,A:A,0)-1,0)
Final cell in your range to sum in column 1 (A), have to subtract 1 from the desired offset (25) similar to the first cell:
OFFSET(A1,MATCH(C2,A:A,0)+24,0)
You can then sum between the offsets
It may seem ridiculous to you but the best non-volatile option is a pair of INDEX/MATCH functions that define the start and stop of your sum range in column B and dispense of OFFSET altogether.
=sum(INDEX(B:B, MATCH(C2, A:A, 0)):INDEX(B:B, MATCH(C2, A:A, 0)+24))
Related
I'm having trouble with an excel formula where i'm trying to get the sum of all numbers in the row which are at 1 column offset with the criteria.
Eg. A1 = Price | B1 = $1000| C1 = Price| D1 = $1500 and so on....
Answer should be 1000+1500= $2500
I tried =SUMIF(1:1,"Price",OFFSET(1:1,0,1)) but gives me error!
I am guessing you have the cell with your formula in the same row, so it is a cyclic reference that gives you the error.
You can cut 1:1 before the cell with the SUMIF:
=SUMIF(OFFSET(1:1, 0, 0, 1, COLUMN() - 2), "Price", OFFSET(1:1, 0, 1, 1, COLUMN() - 2))
a possible solution is to offset your reference ranges. This means you will not be able to do an entire row reference. In your limited example your formula would wind up looking like this:
=SUMIF(A1:Q1,"price",B1:R1)
so you sum range will be limited to one less column than what is available to the sheet to allow for the second range (equal in size range) to be shifted one column to the right.
SIDE NOTE
Idealy you would want to arrange your data in a table. I understand this may not always be possible when dealing with 3rd party data dumps, limited VBA knowledge, and large amounts of data.
SUMIF(A20:ZZ20, "Price", OFFSET(20:20, 0, 1, 1, COLUMN() - 2))
I have the following table and I'm trying to get a formula so that I can get the sum of a center's result between two dates i.e. Sum all numbers for Bunbury between dates 08-05-17 and 06-05-17 (Result: 950). I've used the following formula but it gives me #VALUE!
My formula:
=SUMIFS(INDEX(B:G,MATCH("Bunbury",$A15:$BC15,0),0),$A$16:$A$21,"<=" & $J3,$A$16:$A$21,">=" & $I3)
enter image description here
Your match should match the column, not the row in B:G.
=SUMIFS(INDEX($B$16:$G$21, 0, MATCH("Bunbury", $B$15:$G$15, 0)), $A$16:$A$21,"<="&$J3, $A$16:$A$21,">="&$I3)
'alternate
=SUMIFS(INDEX($B:$G, 0, MATCH("Bunbury", $B$15:$G$15, 0)), $A:$A,"<="&$J3, $A:$A,">="&$I3)
There's also no need to look further than column G for a match and you should start looking in column B; e.g. $B15:$G15. J3 should be the end date and I3 the start date (not evident from your sample image).
I missed one problem the first time around. INDEX cannot reference all of the rows in B:G; it can only reference the same number of rows as $A$16:$A$21 (the date comparison range). Alternately, if there is no rogue data that would skew results, the date comparison ranges could be made full column. They have to be comparable ranges.
Is there a formula without using VB to sum up a total number form a specific range of data?
For example:
Example
I need to sum up the number of times Mary took up the cooking lesson.
I understand that just by using the sum and manually select the range (B3:D3) I will be able to get it. But is there a formula to determine the range (B3:D3) instead?
Please advise. Thanks
The use of the merged cells in row 1 necessitates building a range with a pair of INDEX functions which is then re-examined with another INDEX to pick the row of data with a MATCH function. Once the range has been defined, a SUM function produces the result.
The formula in C10 is,
=SUM(INDEX(INDEX($B$3:$J$6, 0, MATCH($B10, B$1:J$1, 0)):INDEX($B$3:$J$6, 0, MATCH($B10, B$1:J$1, 0)+2), MATCH($A10, $A$3:$A$6, 0), 0))
Fill down as necessary.
I want to use SUBTOTAL to calculate the mean within a range without hard coding in the cell references.
I an currently using the standard:
=SUBTOTAL(1, A2:A11)
But I want Excel to recognise which cells in column A start and end possessing values. So I can specify cell A11 in a separate cell using:
=ADDRESS(MATCH(9.99999E+307, A:A), 1)
Which returns "$A$11". However, If I combine the above equations thus:
=SUBTOTAL(1, A2:ADDRESS(MATCH(9.99999E+307, A:A), 1))
I get an error. I have also tried INDIRECT in combinations with these but that does not work either.
Use the INDEX function to supply the latter half of the cell range.
=SUBTOTAL(1, A2:INDEX(A:A, MATCH(1e99, A:A)))
I want to calculate the sum on a column and then subtract sum on another column BUT using only the values from a given row to the current row (the one in which formula resides).
So, in an "informal custom language", I would need something like this:
Suppose I am in C5: =(sum(A1:"A"+ROW())-sum(B1:"B"+ROW()))
How can I write a correct expression in Excel for this?
You can try using INDIRECT, which accepts a string reference to a range and returns the range itself:
=SUM(INDIRECT("A1:A"&ROW()))-SUM(INDIRECT("B1:B"&ROW()))
Here, we start with a 'stub' of "A1:A". We then get the current row with ROW() (so 5 in this example) and concatenate it with our stub, giving us INDIRECT("A1:A5"). Since INDIRECT will return the range referenced by its argument ("A1:A5" here), we can wrap it with the SUM formula to get the result (which is identical to SUM(A1:A5)). We then do the same thing for column B.
I think you may be looking at it backwards. You need to anchor the first cell reference in the call to SUM to the first row, but let the second cell reference change with the row. Try this in cell C1:
=SUM(A$1:A1) - SUM(B$1:B1)
Now when you copy that down the column, it becomes:
C2: =SUM(A$1:A2) - SUM(B$1:B2)
C3: =SUM(A$1:A3) - SUM(B$1:B3)
C4: =SUM(A$1:A4) - SUM(B$1:B4)
C5: =SUM(A$1:A5) - SUM(B$1:B5)
C5:= (SUM))-(SUM))
Try this:
C5:= (SUM(INDIRECT("A1:A" & ROW()))-(SUM(INDIRECT("B1:B" & ROW()))