![]() |
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.) |
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 |
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 |
Glad to help!
|
All times are GMT +1. The time now is 03:59 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com