Macro for several worksheets

J

JDP

I have a spreadsheet with several workbooks. I would
like to be able to use a macro to delete certain data in
all my worksheets (there are about 25). I have created a
macro to delete the data in just one worksheet but cannot
figure out how to do it in more than one.

Thanks,

Jdp
 
W

Wolf

Hi JDP,

you may use

Sub macro2()
Dim i As Integer
For i = 1 To 25
Sheets(i).Select
'your code here
Next
End Sub

But for this you really need to know that your sheets are
in the right sequence.

Safer is:
make a list of all the sheet-names you want to use, e.g.
putting them in a table from A1 to A25 and name this
range "MySheets"

Then the macro would be

Sub Macro1()
Dim rngName As Range
For Each rngName In Range("MySheets")
Sheets(rngName.Value).Select
'Your code here
Next rngName
End Sub

Best regards

Wolf
 
J

JDP

Thanks Wolf. I think we are getting close. Right now I
am getting a "Compile Error. Wrong number of arguments or
invalid property assignment"

It doesn't like the Sheets parameter in the macro.

Any suggestions?
 
Top