i have a formula like which is trying to sum a range ex: =Sum(C2:C25)
in this i want to change 25 to 26, 27, 28 etc.
Can i declare it as a variable in a cell and how to use it in syntax??
I know how to do it in vba.
Can it be done without VBA???
The formula =SUM(C2:OFFSET(C2;A1;0)), where cell A1 would hold the number of elements to add minus 1, should give the desired result.
Non volatile formula option
INDEX
Similar to what robert used but using a non volatile option. Setup A1 to be the number of rows to sum over.
=SUM(C2:INDEX(C:C,A1+1))
The only caveat to the above, is A1 needs to be an integer greater than 0 I believe.
The difference between a volatile and nonvolatile formula is that a volatile formula will recalculate every time anything on the sheet changes. A non volatile formula will only recalculate when some that affects the formula changes. For a few cells containing volatile formulas, not a big deal. However as the number of volatile formulas increase then moving around your spreadsheet will start to bog down. one way around this is to set calculations to manual instead of automatic.
Related
I would like to make a SUMIFS formula where I can change the sum_range parametr dynamically on the grounds of this formula where I get the column: SUBSTITUTE(ADDRESS(1;MATCH("aaa";1:1;0);4);1;"")
In other words, I want to replace B:B in this formula =SUMIFS(B:B;A:A;"abc") with the formula above. But I am not able to combine those...
I found one solution here: https://stackoverflow.com/a/25814571/10452645
but I'm not quite satisfied with it. Is there another possibility to solve this task by combining SUMIFS and ADDRESS formula.
In the above example, you can find the sum of abc from column aaa using one of the three formulas:
=SUMPRODUCT((B2:D13)*(B1:D1="aaa")*(A2:A13="abc"))
or
=SUMIFS(INDEX(B2:D13,,MATCH("aaa",B1:D1,0)),A2:A13,"abc")
or
=SUMIFS(INDIRECT(ADDRESS(2,MATCH("aaa",A1:D1,0))&":"&ADDRESS(13,MATCH("aaa",A1:D1,0))),A2:A13,"abc")
You can replace aaa and abc with a cell reference so you can "dynamically" change the SUMIFS criteria.
Please note, as mentioned by #ScottCraner
ADDRESS and INDIRECT are volatile and should be avoided. INDEX is the quickest most solid method.
Reason being a Volatile Function is one that causes recalculation of the formula in the cell where it resides every time Excel recalculates. This occurs regardless of whether the precedent data and formulas on which the formula depends have changed, or whether the formula also contains non-volatile functions. It means it could potentially slow down the calculation of your Excel workbook if it gets complicated overtime.
Having that said, choose the function that suits your preference.
I have a use-case with a formula based on integers. It basically takes one value and subtracts an unknown range of numbers from it.
The range of numbers to subtract change every day, but do not exceed 999.
Hence, the formula that I have used looks like this: =B1-(SUM(C1:C999))
Now my problem is, that I need to be able to delete cells in column C without affecting the formula.
I have tried locking the cells like this: =B1-(SUM($C$1:$C$999)), but the formula still changes when I delete cells.
INDIRECT won't work either, cause I'm not working with text strings.
Any ideas?
If you cannot use #RichardHansell suggestion, because you may have data below c999:
=B1-SUM(C:C)
you could use one of these:
=B1-SUM(INDIRECT("c1:c999"))
=B1-SUM(OFFSET($C$1,0,0,999))
Those are both volatile functions so will recalculated when anything changes. For a non-volatile function:
=$B$1-SUM(INDEX($C:$C,1,1):INDEX($C:$C,999,1))
I have a spreadsheet that contains data in columns A:D. Each block of data A1:D11, A12:D22, etc. represents a single days worth of data. It has configuration items that I do a sumif function on to pull for the grand total since the report began(=SUMIF(A:A,L2,B:B). I have now been asked to sum only the last weeks worth of data. My current formula is (=SUMIF(A1:A55,L13,B:B)-very simple. However, I need it to lock so that we only checks data between A1:A55. If I add in a new days block of data it changes the reference to (=SUMIF(A12:A66,L13,B:B). If I use the $ refernce it does the same thing...how do I lock the formula so that it will always look between A1:A55?
Regards
When you do some deletions or insertions, excel will shift the reference used in the formula automatically. e.g. If the original formula in B1 is =SUM(A1:A20), after inserting cell A5 with shifting cells down , the formula will be =SUM(A1:A21).
To avoid this situation, you can use the formula INDIRECT, it will return the reference decided by the argument with string type. Since it is a string, excel will not change its value, therefore the range will always be the same no matter you inserted or deleted something.
So give it a try =)
=SUMIF(INDIRECT("A1:A55"),L13,B:B)
As an alternative suggestion, I would create another column in your table that calculates the weeknumber from the date using weeknum() and then use sumif to lookup a specific week.
That way you don't need to worry about row inserts at all.
By using the Indirect() method (which is a good solution and may be be all you need to solve your problem), you still have the problem of data being inserted into the range that your sumif() covers that might not be part of the week that you're monitoring (for example, if a row containing data from a different week were to be entered into A55).
I am trying to shorten my formula a little and having a hard time figuring out the proper method to do so. I am trying to select certain cells in multiple tables to produce a single total. My code is this:
=SUMIFS(TransactionsChase[INFLOW],TransactionsChase[DATE],">="&Dec,TransactionsChase[DATE],"<"&DecPayChk2,TransactionsChase[CATEGORY],"<>"&"From*")
+SUMIFS(TransactionsPatelcoChecking[INFLOW],TransactionsPatelcoChecking[DATE],">="&Dec,TransactionsPatelcoChecking[DATE],"<"&DecPayChk2,TransactionsPatelcoChecking[CATEGORY],"<>"&"From*")
+SUMIFS(TransactionsPatelcoMM[INFLOW],TransactionsPatelcoMM[DATE],">="&Dec,TransactionsPatelcoMM[DATE],"<"&DecPayChk2,TransactionsPatelcoMM[CATEGORY],"<>"&"From*")
+SUMIFS(TransactionsCash[INFLOW],TransactionsCash[DATE],">="&Dec,TransactionsCash[DATE],"<"&DecPayChk2,TransactionsCash[CATEGORY],"<>"&"From*")
I would love to simplify it if possible into one sumifs statement. Any ideas?
If you apply the four table names within the a SUMIFS function with a volatile INDIRECT¹ function then wrap the whole thing in a SUM function and finalize it as an array² formula, the formula can be shortened visually but not calculation-wise.
In the following image, your original formula is in J2. The revised formula is J3 as,
=SUM(SUMIFS(INDIRECT(N$2:N$5&"[INFLOW]"),
INDIRECT(N$2:N$5&"[DATE]"), ">="&Dec,
INDIRECT(N$2:N$5&"[DATE]"), "<"&DecPayChk2,
INDIRECT(N$2:N$5&"[CATEGORY]"), "<>From*"))
Results should similar to the following. Note the minor improvement made to the , "<>From*" criteria. The table names could also be written out longhand. Instead of N$2:N$5 as,
{"TransactionsChase", "TransactionsPatelcoChecking", "TransactionsPatelcoMM", "TransactionsCash"}
As you can see from the sample image above, this formula will survive tables of varying row length. The only question that remains would be 'Is it worth it?'
¹ Volatile functions recalculate whenever anything in the entire workbook changes, not just when something that affects their outcome changes. Examples of volatile functions are INDIRECT, OFFSET, TODAY, NOW, RAND and RANDBETWEEN. Some sub-functions of the CELL and INFO worksheet functions will make them volatile as well.
² Array formulas need to be finalized with Ctrl+Shift+Enter↵. Once entered into the first cell correctly, they can be filled or copied down or right just like any other formula. See Guidelines and examples of array formulas for more information.
Is it possible to prevent calculations happening to a single cell in Excel sheet? Let's say I have 1001 cells that are very fast to calculate, but 1 cell slows sheet down, is it possible to disable calculations for that 1 cell only?
What I'm NOT trying to do:
Disabling all of cell calculation programically
Calculating specific cells programically while global calculation is set to manual
Use Excel's =IF() function. It is set up to "short-circuit" -- it only evaluates the second parameter if the first parameter is true, oppositely for the third parameter.
So, if the cell is C1, and the cell's formula is currently
=LOOKUP(2,1/(A1:A100000=666),B1:B100000)
and you want it to only be calculated when D1 is true, use
=IF(D1,LOOKUP(2,1/(A1:A100000=666),B1:B100000),C1)
Notice it's a circular reference -- it's how you keep the value the same when D1 is false. Turn on iteration if you want to get rid of the warning message.
Another way is to use one of the third-party Add-Ins out there that lets you store a global variable off-sheet and then retrieve it, which would use syntax like this:
=IF(D1,SetGlobal("C1StoredCalculation",LOOKUP(2,1/(A1:A100000=666),B1:B100000)),GetGlobal("C1StoredCalculation"))
SetGlobal() and GetGlobal() can also be written in VBA, though they'll be a tiny bit slower than an XLL, and they'll lose the value if you reset your VBA project.
Excel does not have a method to disable calculation for a single cell.
You could move the slow formula to a separate sheet and use worksheet.enablecalculation to disable calculation for that sheet.
Or you could store the formula somewhere as text, store the result as a value in the cell, then restore the formula when you want to calculate it.
You can use a replacement UDF and take advantage of a lack of volatility.
Say we have a formula like:
=LOOKUP(2,1/(A1:A100000=666),B1:B100000)
Excel will re-calculate this if any cell in cols A or B change, but the UDF
Public Function myudf(r As Range) As Variant
myudf = Evaluate("LOOKUP(2,1/(A1:A100000=666),B1:B100000)")
End Function
will only be re-calculated when its argument changes. So pick a cell and enter:
=myudf(Z100)
make any changes you want to cells in cols A or B and myudf will remain un-re-calculated until you change Z100
You can use the same tiny trick to make "quasi-volatile" versions of =TODAY() or =NOW() for =RAND()
I don't think this can be done. You can turn off automatic calculation in entire workbooks (as you mentioned), but I don't think there is a way to do this on an individual cell.