Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Office 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: Running a Macro when a Worksheet is Activated.
by Allen Wyatt
(last updated February 8, 2020)
Excel allows you to define macros that are executed whenever certain well-defined events occur in the Excel environment. One of those events is when a worksheet is activated. For instance, you could create a macro that defined a custom menu structure whenever a particular worksheet is displayed.
In order to create a macro that runs when a worksheet is activated, follow these steps:
Private Sub Worksheet_Activate() End Sub
Remember that a macro defined in this way is run every time the worksheet is activated, not just the first time. Think about how you use Excel; it is possible to activate a worksheet several dozen times during the course of a session.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (7221) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Office 365. You can find a version of this tip for the older menu interface of Excel here: Running a Macro when a Worksheet is Activated.
Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!
Besides the regular way of displaying formulas, Excel can also display them using what is called R1C1 format. If you are ...Discover More
Macros are often used to process the data in a worksheet. If that data includes dates that need to be processed, you'll ...Discover More
With a little bit of work, Excel allows you to format individual characters of the text you place in a cell. If you want ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
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.