Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. 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: Maintaining the Active Cell.

Maintaining the Active Cell

Written by Allen Wyatt (last updated October 24, 2024)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


An Excel workbook can contain any number of individual worksheets. As you move around within the various worksheets, Excel keeps track of which cell is selected in which worksheet. When you switch to a new worksheet, Excel makes active the cell that was last active within that worksheet. Thus, if you last selected cell F9 in the worksheet, that is the one that is selected when you display the worksheet again, regardless of what was selected in the previous worksheet.

For some workbooks, however, you may want Excel to make the active cell in the selected worksheet the same as the active cell in the previous worksheet. There is no setting to automatically do this in Excel, but there are a couple of things you can try. One thing is to follow these steps:

  1. Hold down the Ctrl key as you click on the tab of the worksheet you want to go to. Two worksheet tabs should now be selected; the one with the bold name is the one that is actually displayed on the screen.
  2. Click on the tab for the worksheet you want to go to. Both tabs should still be selected, but just the one you clicked on should have its name in bold.
  3. Hold down the Ctrl key as you click on the tab of the worksheet you just left.

These steps work because you are "grouping" worksheets. When you do, Excel makes the selected cells the same for all worksheets in the group.

Remembering to use the Ctrl-click-click-Ctrl sequence can be cumbersome, at best. It is also a sequence that can be fraught with danger, because if you forget to do step 3, you could end up making unintended changes on your worksheets. (While you are working with grouped worksheets, any change you make on one sheet is similarly changed on all the sheets in the group.)

These three steps cannot be automated with macros, but you can take a different approach with a macro to accomplish the same task. The first thing you need to do is declare a public variable anywhere within a module of the workbook, as shown here:

Public sAddress As String

This variable, sAddress, will be used to store the current address of the active cell. In the "ThisWorkbook" module of the workbook, add these two macros:

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _
  ByVal Target As Excel.Range)
    sAddress = ActiveCell.Address
End Sub
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    On Error Resume Next
    If sAddress > "" Then Sh.Range(sAddress).Select
End Sub

The first macro is run automatically by Excel any time that the selected cell changes. All it does is retrieve the address of whatever cell is active, and then store that address in the sAddress variable.

The second macro is automatically run whenever a workbook is activated. It checks to see if there is anything stored in sAddress. If there is, it selects whatever cell address is stored there. The error code is necessary in case you select a sheet that doesn't use cells, such as a chart sheet.

This macro approach works great if you only want to make this navigational change in a single workbook or two. If you prefer to make the change "system wide" (so to speak), you must be a little more complex in your approach to the macro. In this case, you need to place your code in the Personal.xls workbook so that it is loaded every time you start Excel. Specifically, place the following code into a new class module of the Personal.xlsm workbook. This class module should be named something descriptive, such as ClassXLApp:

Public WithEvents gobjXLApp As Excel.Application
Private mstrAddress As String

Private Sub gobjXLApp_WorkbookActivate(ByVal Wb As Excel.Workbook)
    On Error Resume Next
    If mstrAddress > "" Then ActiveSheet.Range(mstrAddress).Select
End Sub

Private Sub gobjXLApp_SheetActivate(ByVal Sh As Object)
    On Error Resume Next
    If mstrAddress > "" Then Sh.Range(mstrAddress).Select
End Sub

Private Sub gobjXLApp_SheetSelectionChange(ByVal Sh As Object, _
  ByVal Target As Excel.Range)
    mstrAddress = Selection.Address
End Sub

Next, open the "ThisWorkbook" module of your Personal workbook and copy the following code to it:

Private mobjXLApp As New ClassXLApp

Private Sub Workbook_Open()
    Set mobjXLApp.gobjXLApp = Excel.Application
End Sub

Once you save your Personal workbook and restart Excel, the range in the first workbook that opens will be selected in the next worksheet that is selected.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10562) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Maintaining the Active Cell.

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

Can't Merge Alphanumeric Data Correctly

When you merge data from Excel into a Word document, you may need to do some conditional processing based on the data you ...

Discover More

Unable to Set Margins in a Document

If you find that you cannot set the margins in a document, chances are good that it is due to document corruption. Here's ...

Discover More

Transferring AutoCorrect Entries

One of the helpful tools in Word is AutoCorrect. If you spend a lot of time creating your own AutoCorrect entries, you ...

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

More ExcelTips (ribbon)

Monitoring the Number of Formats Defined

The number of formats used in a workbook can become a problem if you run up against the limit Microsoft hard-coded into ...

Discover More

Understanding R1C1 References

Referring to cells is typically done using a letter and a number, which represent the column and row. That's not the only ...

Discover More

Odd Arrow Key Behavior

Press the up or down arrow keys, and you expect Excel to change which cell is selected. If this doesn't occur on your ...

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}] (all 7 characters, in the sequence shown) 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 2 + 2?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


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.