Auto update adjacent cells? - excel

I have a table in excel which is constantly having new rows added. I then have another sheet (lets call it results) which is referencing this table, and counting the values in each column.
Every time I add a new record/row to my table, the results sheet throws a bunch of errors in every cell that references the column. Because I'm using a fixed range in the formula to count the column, e.g. =SUM(A1:A10), I then need to manually click each cell in results and select 'include adjacent cells' to get the count to reflect the new data. I have loads of cells in this table and I'm adding data daily so this is a very long winded way of doing things.
I'm looking for a way that I can automatically update these cells, either by using a macro, or adjusting the formula so that it will automatically increase the range of the SUM when I add new data.
The best solution I've had so far was to simply define the range to include the row below my last piece of data (i.e. if A10 is my last record, the formula would be =SUM(A1:A11)). This works, and auto increments the formula when a new cell is added. However, if I delete the record from the table for any reason, the formula reverts to only including the range containing data.
In other words, this solution works, but only until I have to delete a record. Is there any better solution that can detect which rows are populated, and auto include them in the formula?

=SUMPRODUCT(INDEX('Sheet1!'A:A,1):INDEX('Sheet1!'A:A,LOOKUP(2,1/('Sheet1!'A:A<>""),ROW('Sheet1!'A:A))))
Using INDEX and ROW reference, deleting cells won't result in broken cell references. LOOKUP is used to calculate the last non-empty cell in column A. This will auto update.
Using SUMPRODUCT instead of SUM makes it an array formula and does not require older Excel versions to enter the formula with ctrl+shift+enter (because of the LOOKUP function)
In Office 365 you could use: =SUM(FILTER('Sheet1!'A:A,'Sheet1!'A:A<>""))

Related

How do you change the default calculated column formula in an Excel list table?

I have a list with a column that did a lookup to another sheet in the workbook. The original formula looked like this: =VLOOKUP([#[Last Name]]&" "&[#[First Initial]],LookupLastF,9,FALSE).
Later the lookup column was moved, so I had to change the formula to lookup column 10 instead of 9: =VLOOKUP([#[Last Name]]&" "&[#[First Initial]],LookupLastF,10,FALSE). I had to manually copy the formula through the column, because there were exceptions -- i.e. some items overwrote the formula with manually entered values.
The problem is every time a new row is inserted into the table, the old formula is copied to the row instead of the corrected formula. So a default based on the original formula must still exist somewhere. How do I change it to the new formula?
You have to delete the content of the whole column and then (re-)apply the formula.
Mixing formula and static values within one column isn't a good idea.
Use three columns instead: calculated value, manual value, result value (where a formula shows the manual value if exists and if not the calculated value)

Excel: Dynamic Range excluding data/rows based on blanks in specific column

Is there a way to remove from a dynamically generated range full rows based on whether there are blank cells on a specific column within the data that generates that dynamic range?
For example, from the data shown in below table:
I would need the data in the dynamic range to have only the below highlighted data/rows:
The newly created dynamic range would be used in a pivot table and I would like to it to group the dates (therefore the need to remove the blank rows within the range). Please also note that the original list will be updated regularly and would expand (vertically).
You can use the following:
=IFERROR(INDEX($B$2:$C$9,SMALL(IF($C$2:$C$9<>"",ROW($C$2:$C$9),9999999),ROW(A1))-1,COLUMN(A1)),"")
Array Formula Ctrl+Shift+Enter instead of just Enter and drag it in the same row and down
The formula checks if any value in the row is empty (Name or Birthday) to skip the row and look down it
Small will find the smallest row, Row(A1) will change to Row(A2) when drag it down
Column(A1) to copy the first column will become Column(B1) when you drag in the same row
Change B2:B9, C2:C9 and B2:C9 to correspond your Data(last row) and keep $ for fixed references

Selecting a Specific Column of a Named Range for the SUMIF Function

I am trying to create a SUMIF function that dynamically adds up values in a specific column of a named range in my Excel sheet.
It is very easy to do this when there is no named range :
The formula picks out all the cells that contain "London" in their name and sums up the expenses related to London.
What I am trying to do is to use a named range called TripsData (A2:B5) and tell the SUMIF function to sum the entries in the column 2 of this range that meet the criterion of having London in their name.
How can I make this work without needing to create a second named range for column 2 and simply by telling Excel to look within the specified column of this named range? Index/Match only return one value so that doesn't work when there are several cells with London in their name.
Thanks for your help!
Use INDEX to refer to a specific column in the named range (it can refer to a whole column), like this
=SUMIF(TripsData,"*London*",INDEX(TripsData,,2))
You can do that without any named ranges at all, if you turn your data into an Excel Table object. Select any cell in the range or the whole range and click Insert > Table or hit Ctrl-T.
There will be a dialog that asks if your table has headers. Yours does. Now you can reference the table and its columns by their inherent names and build your formula like this:
=SUMIF(Table1[Expense],"*London*",Table1[Cost])
You can rename the table, of course, even after the formula is in place. When you click a cell in the table, there will be a new ribbon for commands that relate to tables only. It's a very powerful tool.
Any formulas, formatting etc. that apply to a whole table column will automatically carry over into new table rows. The table column reference will adjust automatically, too, of course, so you don't have to mess with dynamic range names or re-define what a named range applies to.
Note: the formula uses structured referencing instead of cell addresses. This option can be turned off by clicking File > Options > Formulas > tick or untick "Use table names in formulas"
You can use Chris' idea of Index(Table1,,Col#) with the named range "Table1" (without creating an Excel table Object if you don't want to for some reason) and STILL avoid the problem Applez mentions in the comment below Chris' idea. Applez warns that using a constant for a column number reference is dangerous if you later insert another column before that column in the named range. You will find that Excel does NOT auto increment the constant, so your formula breaks.
Applez is right..... so DON'T use a constant, use a column number "reference" instead of a constant. For example....
=SUMIF(TripsData,"*London*",INDEX(TripsData,,Column(B1)))
If you later insert a column between A and B, Excel WILL auto increment the reference Column(B1) to Column(C1). Just don't delete B1 or Row 1 or you will get a REF error. I usually use the the header/tile "cell" (in whatever row that is in) for that table column within the Column reference (as it is highly unlikely I will ever delete the header/title cell of column of a table unless I delete the entire column). In this particular example as it turn out, B1 "IS" the the title/header cell for that column in the data table. So that is what I used for the example.
Awesome formula, just in case anyone needs to use a similar approach to FILTER a range. I used this approach
pmGendHC is the range I wanted to filter (I expect a spilled range with my data) I needed a colum (column number 13) to be different than 0
=FILTER(pmGendHC,INDEX(pmGendHC,,13)<>0)

Sum/Count Formulas auto adjust for inserted rows

Looking to create a sum and a count formula that will automatically adjust itself for new rows that are inserted within the range.
For example if I have the formula in cell D55 =SUM(D17:D54). Every time I insert a new row within that range, I need to change the top range of my formula to account for it.
Is there a way to write a formula that will automatically adjust itself, so that every time I add a new row I will not need to change my summation formula?
Try
D55: =SUM(INDIRECT("D17:D"&ROW()-1))
This should dynamically adjust to added rows since when adding rows at row 17 the current value at D17 shifts to D18 and no value is present at D17. INDIRECT() should take this into account. ROW()-1 ensures that even when rows are added immediately preceding the formula these are still taken into account.
Edit: I should have added that this can be applied to any formula. Simply replace the range part of your formula with the INDIRECT.
And a quick explanation: the INDIRECT creates an Excel reference from a string so you can construct your formula using dynamic objects. The ROW part of the formula acts as the dynamic factor which is completely dependent on the row count that you add but is independent of the position at which you add your new row.
I think people are misunderstanding. You're inserting a row at the TOP of your range correct?
If so, I would suggest formatting the range as a table. That way your table could look like this:
And the sum function would be simply:
=SUM([Data])
when a row is inserted above the 7, everything is automatically updated.
You might want to have a look at this excellent link that talks about using tables to hold your ranges. This would be my recommendation ... wrap your data in a table. This will create a structured yet flexible reference.
As is noted here, and also from experience, "Because table data ranges often change, the cell references for structured references adjust automatically. For example, if you use a table name in a formula to count all the data cells in a table, and you then add a row of data, the cell reference automatically adjusts."

Efficiently update (growing) columns of data+formulas, w/ automatically updated rows of data

I have columns of data, each cell is a formula referencing data from several rows on another sheet (based on a dropdown box).
I now need to update many columns at once and simply copying the formula down into the next cell in the column, Excel tries to match the 'wrong' cells - the column is going down, the rows are going across, meaning I'd have to type in the correct cells manually every time I copy down this formula.
The rows are updated daily with pulled data/VBA and I can't touch the formatting of the columns either.
Not sure how to do this quickly. I have dates placed down each row/column, if that could be used somehow.
Shown: 2 different sheets, example of 2 rows a single cell will reference. There are many of these rows and columns. This is the formula:
=IF($B$7=1,'xx'!L619,IF($B$7=2,'xx'!M619,IF($B$7=3,'xx'!N619,IF($B$7=4,'xx'!Q619,IF($B$7=5,'xx'!Q619,0)))))
When copying the cells down, the formula updates L619, M619... with L620, M620... when instead I'd need P619, Q619...
This may help if you adapt it to your situation:
You can use the OFFSET or INDEX functions to set your spreadsheet up in such a way to transpose a horizontal row of data into a vertical column of data (and be able to drag the formula).
The trick is, you need a column (you can even hide it) with your increments in the cells i.e. 0,1,2,3,4,5,6,7...n
For example:
A1:A101 are where my increment values from 0 to 100 are.
my horizontal data starts at E15, and continues on with F15, G15, H15, etc.
This is my formula:
= OFFSET($E$15,0,$A1)
When I drag this down in a column, it corresponds exactly to the horizontal rows of data. The same thing can be done using INDEX.
Your situation sounds a little more complicated, but you might be able to build on this to suit your needs.

Resources