Cleaning Sheets

  • Thread starter Thread starter halem2
  • Start date Start date
H

halem2

Hi:

I have a macro that clears the content of different cells in a
worksheet and it works fine. The problem is that our workbooks some
times have over 50 worksheets and the macro has to be ran manually 50
times one per sheet.

is there a way to run it on all sheets but playing the macro only
once???
 
No, but you can loop through the workbook:

Public Sub ClearContentsAllSheets()
Dim wsSheet As Worksheet
For Each wsSheet In ThisWorkbook.Worksheets
wsSheet.Cells.ClearContents
Next wsSheet
End Sub
 
hi,
this might work
Sub Test()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
On Error Resume Next
call YourMacro
On Error GoTo 0
Next ws
End Sub
 
Sub Trigger()
for each sh in Activeworkbook.Worksheets
sh.Activate
myMacro
Next
End Sub

assume your current macro is named MyMacro. Edit the above code to reflect
the actual name of your macro.
 

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