PDA

View Full Version : (Limited) Loop Through Sheets.



lijon
09-29-2008, 08:46 AM
Hi folks, I found this code below to loop through all worksheets in a book.

How can I mod it so it only loops through worksheets I specify and not all of them in the workbook.

Thanks!



Option Explicit

Sub LoopThroughSheets()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets

'** Perform code here **

'E.g.
On Error Resume Next 'Will continue if an error results
ws.Range("A1") = ws.Name

'***********************

Next ws
End Sub

Bob Phillips
09-29-2008, 09:06 AM
Dim ws As Worksheet
For Each ws In Worksheets(Array("Input", "Display"))

'** Perform code here **

'E.g.
On Error Resume Next 'Will continue if an error results
ws.Range("A1") = ws.Name

'***********************

Next ws