Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. 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: Deleting Worksheet Code in a Macro.
by Allen Wyatt
(last updated August 16, 2018)
Jean-Louis would like to write a VBA procedure that deletes the code attached to a specific worksheet. He knows how to delete procedures stored in modules, but not how to do it when they are stored in the sheet.
The good news is that if you know how to delete macros within a module, you can apply the same technique to delete it within a sheet. The difference is that you would use the sheet name rather than the module name when referring to the component you want to delete.
For instance, if you are referring to code in a module in a workbook, you normally do it by referencing the containing module in this manner:
To refer to code contained within a worksheet, you would use this syntax, instead:
For other ideas about how to reference VBA code in various ways from within other macros, refer to the following page at Chip Pearson's site:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9490) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Deleting Worksheet Code in a Macro.
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!
Disabling function keys is rather easy to do when you rely on the OnKey method in a macro. This tip looks at how you can ...Discover More
If your macro closes workbooks, you'll want to make sure that it will save any changes you made to the workbook. Here's ...Discover More
You can easily add a button to your worksheet that will allow you to run various macros. This tip shows how easy it is.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.