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 January 17, 2015)
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.
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!
Strings are used quite frequently in macros. You may want to swap the contents of two string variables, and you can do so ...Discover More
Sometimes, when you upgrade to a new version of Excel, you could run into a problem recording macros that you had no ...Discover More
Macros are often used to process information in a worksheet. You may need your macro to change the values stored in ...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.