Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, and 2016. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Relative Worksheet References.

Relative Worksheet References

by Allen Wyatt
(last updated March 15, 2017)

10

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.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12141) applies to Microsoft Excel 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Excel here: Relative Worksheet References.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Slowing Down Mouse Selection

Ever tried to select a range of cells using the mouse, only to have the cells scroll by so quickly you can't make the ...

Discover More

Showing RGB Colors in a Cell

Excel allows you to specify the RGB (red, green, and blue) value for any color used in a cell. Here's a quick way to see the ...

Discover More

Word's Native Measurement Unit

Word allows you to specify distances using a number of different measurement units. Figuring out how those measurement units ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (ribbon)

Grabbing a User's Name from Excel

One of the settings you can make in Excel is to specify a user's name. This name is accessible through macros, and can ...

Discover More

Arranging Workbook Windows

If you find yourself working with a number of different workbooks at the same time, you may want to arrange your desktop so ...

Discover More

Excluding a Specific Add-In at Startup

Got an add-in that you don't want loaded each time that Excel starts up? Here are a few ways that you can exclude it.

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is nine more than 8?

2017-01-03 15:22:29

Steve Bondy

I tried this but kept getting a #Name error. For anyone else that runs into that, you MUST put the macro in a user module. In the VB editor click on the insert menu, then click on Module.

Paste the VB code into the newly created module, then it all works properly. You can't put the code in the "This Workbook" module, or in the module for one of the individual sheets. It must be in a user module.

See the first two steps of this article for further reference:
http://www.dummies.com/software/microsoft-office/excel/how-to-create-custom-excel-functions/


2016-07-15 11:40:49

Ashley

I am trying to set this up and I keep getting #Value error. I set this up through the VBA which is what I assume you mean when you say create a macro. That is the only way it would work. PreSheet comes up but once I enter the cell vaule for the previous page I get the error. Please help, thanks


2015-11-01 00:44:01

CKChan

Thanks, it's really useful.


2015-10-05 09:22:54

TimZ

Thanks, I think this will will come in handy. In the past, I've relied on named references or used the INDIRECT function to simplify relative references across sheets, but both those options come with some overhead.


2015-08-26 02:45:42

Rajeswar Rao NLV

I have tried this exact macro and it worked for me. It has saved me from enormous work. PrevSheet function is working fine in Macro enable workbook of office 2007 and 2010.
Thank You ExcelTips.


2015-08-04 08:09:04

Blak11

How would I modify this macro to skip hidden sheets..?


2015-02-17 11:46:25

Jeremy

I have tried this exact macro multiple times. I keep getting the return value of "#VALUE!". I know the macro is correct I have copied it from this website. Any ideas of what I could be doing wrong?


2013-03-20 11:20:39

Aldo Santolla

I tested the function and it actually does depend on the order of the tabs along the bottom. The function looks for the sheet previous to the sheet the function is used in. You will get a #VALUE! error if you use this function on the first sheet/tab of the series.


2013-03-19 14:12:53

Dennis Costello

In the above, "which worksheet is before it" depends of course not on the order of the tabs at the bottom of the window or the names of the worksheets, but their index numbers, which roughly translates to the order in which they were created. Sheet1, Sheet2, and Sheet3 are a special case in that when a new workbook is created, they have indices 1, 2, and 3.


2012-09-24 19:16:33

Glenn

Nice one, thanks Allen


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.