Dynamic sum ranges while adding rows above first row and below last row - sum

I have sample numerical data from A2 to A5. The sum is displayed in A6. I wish to hold the range as dynamic while summing. Hence, I used the following formula in A6
=SUM(A2:OFFSET(A6,-1,0))
The above formula considers extra rows that are added below A5 only. If I add cells above A2, they are not being considered in the calculation of sum. How should the formula be modified in order to consider the rows above A2 also in the sum?
Note: I am aware that =SUM(INDIRECT("A6:A"&ROW()-1)) is a solution to this problem. But, the difficultly I am facing is that, when I copy this sum formula to a different cell, the reference inside the quotes has to be modified manually. Hence, I desire a formula such that I need not modify the reference cells manually each time when I copy the SUM formula.

I tried this formula and it works
=SUM(A1:OFFSET(A6,-1,0))
I am posting this for the benefit of the community. As explained previously, even though =SUM(INDIRECT("A6:A"&ROW()-1)) is a solution to the problem, one has to edit the reference manually, which is cumbersome. I hope this helps others in this forum.
Note: Select one cell above the first cell from which sum is to be calculated

Related

Conditional formatting 1 cell based on cell input on another sheet, apply to entire row

For work I need to create a resource management excel file. My goal is to create an overview as is seen here:
If John would have taken a few hours off, or if he has a fey hours of sick leave, I would like to turn this cell only to change colour so I know that John will be absent for whatever reason on this day.
However, since I'm creating this for an entire row (for a whole year), I do not want to create conditional formatting per cell because that would be plain madness.
Here is an example per employee (in this example John):
enter image description here
So what I need is a formula to check if a cell in a row (for example sick leave) on the employee worksheet is grater than 0 and then change the colour of only the corresponding cell on the recourse planning worksheet, not the entire row.
Does any of you guys know if this is possible in excel 2016? Preferably without VBA scripting since I have to transfer this excel file to a co-worker who is not into VBA programming.
Thank in advance.
Nuntius transmittendus!
This is definitely possible without any code. Use CountIf() as tinus087 commented. The tricky part is how to create the address range used by the CountIf() so that you can put one conditional format on all the cells. On the the one hand you need the column of the cells being checked to match the column of your total cell. On the other hand the worksheet tab name needs to change depending on which row you are on. So use INDIRECT() to point to the correct worksheet and OFFSET() to look at the correct cells.
So, for cell C4, the formula you want to use as the range in your CountIf() is OFFSET(INDIRECT($A4&"!A1"),3,COLUMN(C1)-1,4). When applied to cell C4 this creates address John!C4:C7. When used for cell D4, it results in John!D4:D7.
You'll probably want some error checking to deal with the #REF! error happens when the formula is applied to a row without a first name or where the name listed doesn't match any worksheet tabs.
Something else to think about, if you haven't already, what happens if there are two John's? Is the 2nd John going to be named John2?

IfError, leave formula in place/don't do anything?

I have a spreadsheet, where I'd like to drag down a particular index/match formula, but where the formula does not return a value, I'd like it to keep the formula that is already in place (which sums up a few of the items below it).
I know that you could just use the cell reference for the if_error part of the formula, but this would return the value of the cell as it is now, and wouldn't use the current formula to generate a new value based on the values returned by the index match formula.
I have attached pictures below. Basically, I want to leave the sum formulas as is, but just be able to drag down that first index formula (the actual spreadsheet I'm dealing with has many different spaces, and is very long, otherwise I'd just copy the formula manually).
If this isn't possible, are there any other solutions? Another thing I tried was for each index/match that didn't return a value, I had it return the formula as a string, and then I'd copy/paste special with values, replace the column in the formula that is a string to the column I'm looking for, and then it would evaluate the formula that was, before, a string. But then you lose the formulas for all the other cells.
So the issue is that some cells are used to sum, and I don't want to drag the formula over those cells, but at the same time, I do need to use the formula over the whole range, otherwise it would just take too long.
Once you put a formula in G1, the previous formula in that cell is no longer available, so referencing G1 in your new formula would just produce a circular reference.
Instead think of a formula that combines both formulas into one: it should detect in which situation it is and then perform the appropriate calculation.
In your case, I think this formula will do what you want:
=IFERROR(INDEX($M$3:$M$9, MATCH(F1,$L$3:$L$9)), IF(E1="", "", SUM(G2:G4)))
Put it in cell G1 and copy it down.
Note how it looks at column E to decide whether it should do the sum. I also adapted a bit the part you already had, by making some references absolute (adding some $), because the area in the L and M columns is positioned at fixed rows.
Add a helper column in row H for your Index-Match formula and copy it all the way down. Then, in row I do an if statement. If row H meets the criteria you want, do that, else use row G.
So I think I found a good solution, especially in the case where you are going to be using the spreadsheet over and over, and the format won't change much. This might be too specific for anyone to use, but posting it just in case someone gets some use out of it.
First I created two macros, one to hide the sum rows, and another to unhide all the sum rows. I got the sum rows from another column by copying all the formulas across to the new column I'm looking at. Numbers will of course be wrong, but the sum formulas will be what we want to keep. You can speed this up by finding "sum" in formulas and then selecting all of the results.
Next, use the macro which hides all the sum rows.
Next, create the index formula in the first row. Control shift down to select all rows beneath. Then, "find", and "go to special" and select "only visible cells", and then hit F2, and control enter, and this will copy the formula down to all the visible cells, ie the non-sum cells.
Then use your unhide macro, and it should be golden!
You can use this technique for any spreadsheet where the source data format is different from target, and where you have fixed formulas in the target which you always will need.

Excel formula not working as expected

I have a sheet that shows max values spent anywhere. So I need to find most expensive place and return it's name. Like this:
Whole sheet.
Function.
Function in text:
=IFS((A6=MAX(D2:D31)),(INDEX(C2:C31,MATCH(A6,D2:D31,0))),(A6=MAX(H2:H31)),(INDEX(G2:G31,MATCH(A6,H2:H31,0))),(A6=MAX(K2:K31)),(INDEX(K2:K31,MATCH(A6,L2:L31,0))))
Basically I need to find a word left to value, matching A6 cell.
Thanks in advance.
Ok.. Overcomplicated!
Firstly, why the three rows? it's a lot easier if you just have one long row with all the data (tell me if you actually need 3 I'll change my solution)
=LOOKUP(MAX(D2:D31);D2:D31;C2:C31)
The MAX formula will lookup the biggest value in the list, the Lookup formula will then match it to the name.
Please note: If more than one object has the maximum price, it will only return the first one. The only way I can think of to bypass that would be to build a macro.
EDIT:
Alright.. Multi Column solution is ugly and requires extra columns that you can just hide.
As you can see you'll need 2 new columns that will find the highest for each row, 2 new columns that will find the value for each of these "highest" (in this case tree and blueberries) and then your visible answer will simply be an if statement finding out which one is bigger and giving the final verdict. This can be expanded with an infinite number of columns but increases complexity.
Here are the formulas:
MAX(H2:H31)
LOOKUP(A5;H2:H31;G2:G31)
MAX(L2:L31)
LOOKUP(C5;L2:L6;K2:K6)
IF(A5>C5;B5;D5)

VBA- Need help to do average rows if data present in the other columns

I have a excel sheet which we may keep adding rows/ deleting them.
And I have an average value present in some cell.I would want the excel formula to identify if there is text in another column to average the columns
So now if I insert another row, I have to manually update the average formula.
Is there a way to have a formula which check if column A is not empty, it should consider the data in column G for the average
There's a lot of approaches to this. My current favourite is a CELL:INDEX(...) expression. For instance, to find the last populated cell in the first continuously populated range between B1 and B5000, I would use (probably as a named range) $B$1:INDEX($B$1:$B$500,MATCH(TRUE, $B$1:$B$500="", 0)-1).
This approach is great because it's non volatile, so it shouldn't bog your worksheet down. It might be vulnerable to $B$500 gradually shrinking if you're only ever deleting rows, though. Alternatives are referencing the whole column ($C:$C), but that's usually dog slow in modern excel, or using OFFSET which never shrinks, but is volatile.

Use Excel/OpenOffice cell names within drag-completition

I have a lot of measured values in each column. I use formulas under those values to calculate with them. I always edit the first column and drag-complete (small square in the south-east of the selected cell) to change the other columns, too.
It was fine while dealing with 5 values, but with 20 values in a formula, things are getting complicated. I would like to use cell names, as I found in Variable in Excel, but when I use drag-complete, this cells are not adapted for the next column, like $D$1 does instead of D1.
Ideas for solutions:
Perhaps I can declare an row of cells as an array and index it with cellname(row), but how is this possible?
Perhaps it is easier with a small vba script, but I would like to avoid this.
Thanks in advance.
Edit 1:
I was afraid that my question is not that clear. I will try to clearify it with the following files. Thus the Excel-Tag is removed, I uploaded an ods-File:
My file looks like the uploaded short example example.ods.
I created cell names in the second column like "size". Then I have put a human readable formula like "=size+step+thickness*weight" in C7. When I drag-complete it to cells D7 and E7 like shown in example.png. I get of course the same result as in C7, because the cell names are used as absolute names like $B$2 for example.
How can I have human readable formulas applied to D7 and E7 without editing D7 and E7 by hand? When I use for C7 "=C2+C3+C4*C5", I can use the drag-completition of course.
I hope this is more clear now. I guess this is some basic functionality, but I just don't know how to describe it well. Perhaps you have a similar idea to have it more readable than "=C2+C3+C4*C5".
This works in OpenOffice.org Calc as well as in LibreOffice Calc, but it's crucial to define the cell names for every column that will be evaluated by the formula. Here's a step-for-step solution, based on the example document:
Start with a spreadsheet containing just the values together with row and column heads:
Create the cell range names:
a. Select the data range including the column holding the row names (OOo will use those Strings as names in the next steps):
b. Select "Insert -> Names... -> Create":
c. Select "Left Column" to name the rows based on the content of the first column:
Result: four names, one for each row, named as desired:
Create the formula for the first data row (here incomplete, demonstrating OOo's tooltips):
Drag-complete for all other data rows, giving the final result (with Tools -> Detective -> Trace precedents activated - the detective points to the array's first column, but the formula will use the values of the current column):
You can use relative references in Names, it easier to use R1C1 mode for this:
Define a Name Size with a RefersTo of =R2C
Then wherever you use the name Size in a formula it will refer to the current column and row 2