Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB Excel - Global Macro run when columns are added / removed

Status
Not open for further replies.

remeng

Technical User
Jul 27, 2006
519
US
Hi,

Is there a way to create a global macro for a workbook that is triggered when columns are added or removed from specific sheets within a workbook?

The goal is to alert the user that adding or removing columns may prevent the other macros from working. Another option with the alert box might be to undo the last add column or delete column operation.

Any ideas?

Thanks,

Mike
 
Not directly, workbook level event procedure [tt]Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)[/tt] returns sheet reference Sh, it is possible to test if it is the specific sheet, and Target, [tt]Target.Address[/tt] returns whole rows/columns address when they are added or removed (also, when all formulas in row/column change), check this and display warnings or undo.
The [tt]Change[/tt] event procedure can be fired for specific worksheet if it is in worksheet module.

Worksheet protection can be set for adding/removing rows/columns (four options), workbook structure protection can be set to block adding/removing sheets, all without code.

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top