Originally Posted by
Pete_UK
Hopefully the attached file will solve your problems, and give you some time back in your life.
Notice first of all that I have renamed the sheet 12-6 to 12-06. It is important in the formulae which follow that the sheet names are of the format mm-dd, with leading zeros for both the month and day where appropriate.
In all the sheets I have used this formula in cell I1:
=MID(CELL("filename",A1),FIND("]",CELL("Filename",A1))+1,255)
This returns the name of the sheet, and I have coloured it red for emphasis. You can then derive the names of the previous sheets, using this formula in J1:
=TEXT(DATE(2019,LEFT(I1,2),RIGHT(I1,2))-7,"mm-dd")
and this formula can be copied across into K1:L1, to give you 4 sheet names. Note, though, that you will have the change the year (shown in red) to 2020, once you get to next year with more added sheets.
Then, for the sheets which have at least 3 previous sheets, you can use this formula in cell F3:
=AVERAGE(C3,IFERROR(INDEX(INDIRECT("'"&J$1&"'!c:c"),MATCH($A3,INDIRECT("'"&J$1&"'!a:a"),0)),""),IFERROR(INDEX(INDIRECT("'"&K$1&"'!c:c"),MATCH($A3,INDIRECT("'"&K$1&"'!a:a"),0)),""),IFERROR(INDEX(INDIRECT("'"&L$1&"'!c:c"),MATCH($A3,INDIRECT("'"&L$1&"'!a:a"),0)),""))
which will take the average of the current sheet's column C value along with the corresponding value in the previous 3 sheets, so even if a name moves up or down in one or more of those sheets, the value will still be found (there were no examples of this, so I couldn't fully test this out). The formula can be copied down column F where appropriate - I've done this for sheets 12-06 and 12-13.
In the sheets which have only two or fewer previous sheets, I've left the original formulae in column F, and instead put a modified formula in cell I3. Where there are only 2 previous sheets, you only need data from those sheets, so the formula can be shortened. If there is only 1 previous sheet, the formula can be shortened even further, but you can compare the results directly with the results that your original formulae produced.
Going forward, all you need to do is CTRL-drag the latest sheet tab to produce an exact copy, and then rename the new sheet as appropriate and the formulae will automatically adjust. You can move the names up and down as required, and then enter the data for that week. If you add any new names, you should bear in mind that they won't exist on previous sheets, so you can delete from the formula in column F the terms which relate to those weeks, as appropriate.
Hope this helps.
Pete
Bookmarks