automatically apply a macro to all worksheets

M

minrufeng

for example, i create a simple macro for inserting a row above a certai
cell. I want the macro applied to all sheets when running the macro
Does anyone know how to do this? thanks a lot
 
D

Don Guillett

try
Sub insertrowinallsheets()
myrow = ActiveCell.Row
For Each ws In Worksheets
ws.Rows(myrow).Insert
Next
End Sub
 
M

minrufeng

However, if I misoperate a macro to all worksheets and want to undo this
operation, what should I do? Thanks for your great help!
 
D

Dave Peterson

Save your workbook before you run this macro.

If you screw it up, then close that workbook without saving and reopen it.
 
D

Don Guillett

try.
Sub insertrowinallsheets()
myrow = ActiveCell.Row
For Each ws In Worksheets
ws.Rows(myrow).DELETE
Next
End Sub
 
Top