Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Relative Worksheet References.
Written by Allen Wyatt (last updated December 15, 2018)
This tip applies to Excel 97, 2000, 2002, and 2003
Suppose you have a workbook with three worksheets, Sheet1, Sheet2 and Sheet3. In column A1 of worksheet Sheet2 you have the formula =Sheet1!A1. When you copy that formula from Sheet2 to cell A1 of Sheet3, the formula still references Sheet1. How can that be, though? Why doesn't Excel adjust the sheet reference, like it does the cell references?
Like named ranges, Excel treats worksheet names as absolute. Each worksheet object is independent of all other worksheets in the workbook. When you paste a formula that includes a sheet reference, that sheet reference is left unchanged in what is pasted.
There are a couple of things you can do. One is to simply modify the formula reference after it is pasted so that it references the correct sheet. If you have many of them to change, then you can select all the formulas in the target worksheet (F5 | Special | Formulas) and then use Find and Replace to replace the original worksheet name (Sheet1) with the correct worksheet name (Sheet2).
If your referencing needs are not complex, then you can use a macro approach. For instance, if you want a formula in a particular cell to refer to a cell on the sheet previous to the current sheet, then you can do that by macro rather easily. Consider the following macro:
Function PrevSheet(rCell As Range) Application.Volatile Dim i As Integer i = rCell.Cells(1).Parent.Index PrevSheet = Sheets(i - 1).Range(rCell.Address) End Function
The macro looks at the current worksheet and then figures out which worksheet is before it. The reference is then made for that worksheet. Once you've created the PrevSheet macro, here's one way the function can be used in a cell:
=PrevSheet(A1)
This returns the value of cell A1 from the previous worksheet. If you have Sheet1, Sheet2, and Sheet3, and you use this formula on Sheet3, then it returns the value of Sheet2!A1. If the previous sheet is the first sheet of the workbook or it is not a worksheet, then the function returns a #Value error.
If you later copy this formula to a different sheet (say to Sheet 5), then it pulls up the value relative to its new location, which means it pulls up the value from Sheet4!A1.
You can also include a sheet name and the function will work just fine:
=PrevSheet(Sheet3!A5)
This version will always return Sheet2!A5 since sheet2 is the previous sheet of Sheet3.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3088) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Relative Worksheet References.
Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!
Excel allows you to "freeze" rows in your worksheet. What if you want the rows that are frozen to change as you scroll ...
Discover MoreExcel makes copying worksheets (duplicating them) rather easy. However, you may want a worksheet copy that differs from ...
Discover MoreExcel allows the user to determine how many default worksheets are in a new workbook.
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2022-11-30 10:07:01
Dave
Thanks!
If you have a *very special case* where you have two workbooks containing identical sheet names, and you want each sheet to get info from its 'twin', there is another way for this special circumstance:
-first, select all sheets of the first workbook, so that what you enter gets populated to all sheets
-from some cell in the first workbook, enter a formula to find the current sheet name (see: https://excel.tips.net/T003793_Getting_the_Name_of_the_Worksheet_Into_a_Cell.html )
-use " " and & to concatenate with a formula to retrieve the information
-use the "INDIRECT()" function from some other cell in the first workbook
Example:
Place this in Cell A1 (for example) of the first workbook:
="'[second_workbook_name]"&MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,255)&"'!$E$209"
(where E209 is the cell whose contents you want to retrieve from the other workbook, in each corresponding sheet)
Then, in some other cell:
=INDIRECT(A1)
Hey presto...
2019-06-17 08:34:55
Assem
Million of thanks, too useful, but I face a problem when I save the sheet it ask me to save it as Excel Macro Enable Temple in order to activate the function PrevSheet, but when I open the sheet again it give me ( #Name? ) error massage
How can I save the extension as Excel Sheet without problems ???
2019-04-16 18:00:02
Jillian
I tried doing this but using the format: [h]"hrs, "m"min". Whenever I use the PrevSheet macro I get "NAME?". What am I doing wrong?
2019-01-03 11:42:07
Jennifer Batina
You are my hero!!!!! I've been looking for a way to do this FOREVER. I knew there had to be something simple. It's not all that simple for me, but it was easy for me to use what you shared. THANK YOU!
Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments