automatically apply a macro to all worksheets

  • Thread starter Thread starter minrufeng
  • Start date Start date
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
 
try
Sub insertrowinallsheets()
myrow = ActiveCell.Row
For Each ws In Worksheets
ws.Rows(myrow).Insert
Next
End Sub
 
However, if I misoperate a macro to all worksheets and want to undo this
operation, what should I do? Thanks for your great help!
 
Save your workbook before you run this macro.

If you screw it up, then close that workbook without saving and reopen it.
 
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

Back
Top