Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ben Ben is offline
external usenet poster
 
Posts: 509
Default Loop through specific worksheets

I am familiar with the code to loop through all the worksheets in a workbook
with a "For Each ws in Worksheets" construct but I would like a routine to be
confined to a selection of named worksheets within a workbook. Let's say the
worksheet names are in a range called "MyList" in a worksheet called
"Control". What code should I use to apply my routine only to the worksheets
in "Mylist".
Thank you.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Loop through specific worksheets

Hi Ben,

Try something like:

'<<==============
Public Sub Tester02()
Dim SH As Worksheet
Dim rng As Range
Dim rCell As Range

Set rng = ActiveWorkbook.Sheets("Control").Range("MyList")

For Each SH In ActiveWorkbook.Worksheets
If Not IsError(Application.Match(SH.Name, rng, 0)) Then
'Do something, e.g.:
MsgBox SH.Name
End If
Next SH
End Sub
'==============


---
Regards,
Norman


"Ben" wrote in message
...
I am familiar with the code to loop through all the worksheets in a
workbook
with a "For Each ws in Worksheets" construct but I would like a routine to
be
confined to a selection of named worksheets within a workbook. Let's say
the
worksheet names are in a range called "MyList" in a worksheet called
"Control". What code should I use to apply my routine only to the
worksheets
in "Mylist".
Thank you.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Loop through specific worksheets

does this idea help? You do not usually have to specify the sheet name
unless you have duplicate names.

Sub loopthrusheetarray()
Dim Sh As Worksheet
For Each Sh In Sheets(Array("Sheet2", "Sheet6", "Sheet10"))
MsgBox Sh.Range("a1")
Next
End Sub
--
Don Guillett
SalesAid Software

"Ben" wrote in message
...
I am familiar with the code to loop through all the worksheets in a
workbook
with a "For Each ws in Worksheets" construct but I would like a routine to
be
confined to a selection of named worksheets within a workbook. Let's say
the
worksheet names are in a range called "MyList" in a worksheet called
"Control". What code should I use to apply my routine only to the
worksheets
in "Mylist".
Thank you.



  #4   Report Post  
Posted to microsoft.public.excel.programming
Ben Ben is offline
external usenet poster
 
Posts: 509
Default Loop through specific worksheets

Thank you to Don and Norman Both suggestions do the job.

"Don Guillett" wrote:

does this idea help? You do not usually have to specify the sheet name
unless you have duplicate names.

Sub loopthrusheetarray()
Dim Sh As Worksheet
For Each Sh In Sheets(Array("Sheet2", "Sheet6", "Sheet10"))
MsgBox Sh.Range("a1")
Next
End Sub
--
Don Guillett
SalesAid Software

"Ben" wrote in message
...
I am familiar with the code to loop through all the worksheets in a
workbook
with a "For Each ws in Worksheets" construct but I would like a routine to
be
confined to a selection of named worksheets within a workbook. Let's say
the
worksheet names are in a range called "MyList" in a worksheet called
"Control". What code should I use to apply my routine only to the
worksheets
in "Mylist".
Thank you.




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
Loop worksheets merry_fay Excel Discussion (Misc queries) 2 January 7th 09 01:54 PM
Macro/Loop If Statement Help -delete the row with the specific te Bricktop Excel Programming 5 October 28th 05 09:50 PM
Loop thru some worksheets Mike Fogleman Excel Programming 2 August 21st 05 12:22 AM
Loop Through worksheets Stephen[_9_] Excel Programming 5 April 20th 04 01:46 PM
Loop worksheets Steve[_35_] Excel Programming 3 November 25th 03 04:46 AM


All times are GMT +1. The time now is 02:41 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"