Repeating VBA operations

A

Adam1 Chicago

I have several hundred lines of code that look like:

Sheets("First").Select
[LOTS OF CODE HERE]
End of code

If I want to repeat all of the same steps on two other sheets, do I have to
copy and paste the code twice under the names of the two different sheets or
is there a command I can use to repeat all of the code on different sheets?

Thanks

(P.S. I am a total novice, so the easier the solution the better.)
 
D

Dave O

First step is declare a variable to hold the sheet names: I use one
called SheetName:

dim SheetName

Then set up a FOR...NEXT loop to repeat your code for each worksheet:

For each SheetName in Sheets
Sheets(SheetName).Select
[Lots of code here]
Next SheetName
 
Top