How can I reference the cell of
- in the previous row,
- of the same table,
from a cell of the same table? Without relying on the absolute row / column numbers of the worksheet if possible.
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
If you want to use the structured reference format, try
You can also do this without using structured references. For example, in row 2 of the table (the first data row), enter
... if "Colour" is in column D. (Adjust to your situation). The latter will be much faster in large datasets, since Offset() is volatile and will recalculate whenever ANY cell in the workbook changes. That can greatly impact performance.
I almost always create a separate column in my table named "I" for index, which is numbered 1,2,3,4...
Then to get the previous value use
You can also number it the column starting from 0 and adjust the formula accordingly, since you almost always access the row before.
OFFSET function causes my large workbooks to crash so I recommend to avoid at all costs.
I know this is an old post but just like I needed something similar now, i'm sure this may be of help for someone later. If what you need is to do a running sum on a table column, for example:
For each row, you need to add the previous balance (Column 2, previous row) and the income (Column 1, current row) to calculate the current balance.
One way to do that is using this formula in the Column 2, based on teylyn's answer:
This will handle some errors occurring in the first row
Want to follow up on some other answers and comments.
Some folks have suggested to use a formula such as suggested by @teylyn on 2013-06-29 10:47:
But as @DasistLars pointed out in an answer on 2018-11-09 07:35, this is a volatile function, so is not good to use if your workbook will have lots of data. @DasistLars suggested to create a column called "I" numbered 1,2,3,4,etc... and use the formula:
... which is a great suggestion, as INDEX is not volatile.
I will add to this that a way to get column "I" to autopopulate with the line number is to use this formula (example with the formula in cell A2, with that being the first non-header row in the table):
This will add 1 to the value in the row above, which can't be done for the first row, so it enters 1 in that case. It's important to have the formula in the first row of the table, as new rows take the value/formula from the first one.
In the comment thread to @DasistLars answer, there are a couple of comments suggesting to use a formula with the function ROW in it, but that function is also volatile so doesn't really solve the problem.