I have a monthly sheet w/ dated tabs.
I am looking for the formula for the difference between today's data (in the cell) and data from previous day's tab.
Today is the 30th so what I am currently using looks like this:
=C2-'29th'!C2
However, each day I have to update the date in the formula for that column.
I want one I can copy.
Best Answer
You might be looking for some modification to the
=INDIRECT()
function. This lets you reference a cell by sort of "spelling out" a reference string like29th!C2
. I'll walk through how you'd build such a formula, sticking to your=C2-'29th'!C2
example.Let's assume you put that formula in cell C3. It's taking some number from cell C2 on the 30th and seeing how much it's changed since the 29th.
The first step is adding the INDIRECT formula. We'll change the formula to be
The INDIRECT formula is merely taking a cell reference as a string and getting the contents of that cell.
Now we need to change INDIRECT so that instead of always looking at the 29th it looks at yesterday's date. To do that, we need to figure out what today's date is and subtract one. We might think to use the
TODAY()
function, except if we do this every tab in the spreadsheet will think it's today. Instead, we want each formula to find "yesterday" based on the name of the spreadsheet tab that it's sitting in, so that a formula on the30th
tab will look at29th
, a formula on the15th
tab will look at14th
, etc.Unfortunately, spreadsheet formulas can't get the name of the tab they're on, and I'm going to assume here that you don't want to mess with the script editor. A viable alternative would be to write the date somewhere inside the tab, like for example cell
A1
. So on the30th
tab, we'll put30
in cellA1
. On the29th
tab, we'll put29
in cellA1
, and etc for each spreadsheet tab.We can now tell the INDIRECT function to look at cell
A1
and find the date one before it, like this:The only problem now is that the formula is trying to find cell
C2
on a tab called29
. We need it to look at the29th
tab.Unfortunately, there isn't a great way of doing this. Personally, I would suggest renaming the tabs from 1st, 2nd, 3rd to 1, 2, 3, etc. But, if you're set on the current format, you could replace
A1-1
in the current formula with something like this:This would give you a finished formula:
For the sake of not having such a huge formula though, I'll assume that the tab names do not have th, st, and rd in them.
At this point you should have something resembling this screenshot. The number of the current tab is in the top left, and the calculated difference is in C3 in this case.
The formula being used here can be easily copied to any other tabs without needing to be updated.
On a final note, you may be opposed to the requirement of typing the current tab's number in some cell, like
A1
. There is a possible alternative using the TODAY function, though it requires the formula to be overwritten. If you're updating each tab on its date (meaning you create the30th
tab on April 30th, and that's when the data should update) you can change the formula toHowever, in order to prevent this formula updating when you go to calculate the following day (e.g. all the values on the tabs 1-29 changing when you add data on the 30th), you need to paste the result of this formula as a plain number (no formula) after it calculates. You can do this by selecting the cell with the formula and pressing
Ctrl + C
followed byCtrl + Shift + V
.