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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top