Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Adam1 Chicago
 
Posts: n/a
Default Repeating VBA operations

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.)
  #2   Report Post  
Dave O
 
Posts: n/a
Default

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

  #3   Report Post  
Adam1 Chicago
 
Posts: n/a
Default

thanks again!

"Dave O" wrote:

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


  #4   Report Post  
Dave O
 
Posts: n/a
Default

Glad to help!

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
repeating formulas by the same row or colum increment as the last. Formulas Excel Discussion (Misc queries) 0 February 24th 05 04:55 AM
repeating formulas by the same row or colum increment as the last. Formulas Excel Discussion (Misc queries) 0 February 24th 05 04:51 AM
Header - stop repeating on every page! sararose27 Excel Discussion (Misc queries) 2 February 17th 05 10:41 PM
reference a repeating cell in a formula Tafe Riller Excel Worksheet Functions 1 February 17th 05 03:20 PM
Repeating formula in Excel RescueEMT72 Excel Discussion (Misc queries) 8 November 28th 04 03:37 AM


All times are GMT +1. The time now is 01:14 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"