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: Running a Macro when a Worksheet is Activated.
Written by Allen Wyatt (last updated February 8, 2020)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365
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.
Note:
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 Microsoft 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.
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!
When you record a macro, make sure that you know how Excel is recording your cell movements. This tip explains the ...
Discover MoreNeed to know how many characters there are in a workbook? You can find out easily with the handy macro introduced in this ...
Discover MoreThe macro programming language used in Excel gives you a great many tools that allow you to modify the way that Excel ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2020-07-19 08:33:02
Peter Atherton
Eddie D Faucheux
It is entered in the Worksheet Code. Right-click the sheet tab and pick View Code the code shound be triggered by the sheet Activevate event
Private Sub Worksheet_Activate()
myMacro
End Sub
2020-07-18 13:16:06
Eddie D Faucheux
In this new subroutine enter the macro you want executed whenever the worksheet is activated.
Where do you enter it?
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.
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