Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default For Each Loop with Exceptions

I have a For Each Loop that loops through my sheets and
performs certain actions. Is is possible to set the
routine up so that I can exclude certain sheets from the
loop. That is, if I pass the excluded sheets to a
variable or array, can this variable or array be used in
conjuction with the For Each Loop?

For Each sh in Workbook
Logic here that bypasses certain sheets

Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default For Each Loop with Exceptions

Select sheets to skip by individual name:

If sh.name = "whatever" or sh.name = "something" Then
'do nothing
Else
your code
End if

Use a naming convention if you need to skip a lot:

If left(sh.name,4) = "skip" Then
'do nothing
Else
your code
End if

Steve


"ExcelMonkey" wrote in message
...
I have a For Each Loop that loops through my sheets and
performs certain actions. Is is possible to set the
routine up so that I can exclude certain sheets from the
loop. That is, if I pass the excluded sheets to a
variable or array, can this variable or array be used in
conjuction with the For Each Loop?

For Each sh in Workbook
Logic here that bypasses certain sheets

Next



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default For Each Loop with Exceptions

And I will not know what sheets I am omitting until the
macro runs. So I am assuming that I would have to pass
the sheets include/omit (boolean 1 or 0) to an Array.
Then call up the array within the for Each loop.

Click Box generated with every sheet as option
Choose sheets want to inlude
Pass Click_Event values as boolean to SheetArray
Pass SheetArray to sub

Other Sub ()
x = 0
For Each sh in Workbook
x = x + 1
If Sheet Array(X) = 1 Then
"do something"
Else
"do nothing"
Next
End Sub

What I was wondering was is their a command that allows
you to skip to the Next portion of the Loop? Or is that
just poor coding (i.e. Goto Next)

Thanks




-----Original Message-----
Select sheets to skip by individual name:

If sh.name = "whatever" or sh.name = "something" Then
'do nothing
Else
your code
End if

Use a naming convention if you need to skip a lot:

If left(sh.name,4) = "skip" Then
'do nothing
Else
your code
End if

Steve


"ExcelMonkey" wrote

in message
...
I have a For Each Loop that loops through my sheets and
performs certain actions. Is is possible to set the
routine up so that I can exclude certain sheets from the
loop. That is, if I pass the excluded sheets to a
variable or array, can this variable or array be used in
conjuction with the For Each Loop?

For Each sh in Workbook
Logic here that bypasses certain sheets

Next



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default For Each Loop with Exceptions

If you are going to build a sheet array, why not just include the ones you
want to process - either that or go back to the source to determine which
ones to process. There is no sense doing the same or similar processing 2
or more times.

You can goto a label, but generally, you can handle that with an if
statement

for each
if condition then

end if
Next

is easier to follow than

for each
if condition then goto AA


AA:
Next



--
Regards,
Tom Ogilvy


"ExcelMonkey" wrote in message
...
And I will not know what sheets I am omitting until the
macro runs. So I am assuming that I would have to pass
the sheets include/omit (boolean 1 or 0) to an Array.
Then call up the array within the for Each loop.

Click Box generated with every sheet as option
Choose sheets want to inlude
Pass Click_Event values as boolean to SheetArray
Pass SheetArray to sub

Other Sub ()
x = 0
For Each sh in Workbook
x = x + 1
If Sheet Array(X) = 1 Then
"do something"
Else
"do nothing"
Next
End Sub

What I was wondering was is their a command that allows
you to skip to the Next portion of the Loop? Or is that
just poor coding (i.e. Goto Next)

Thanks




-----Original Message-----
Select sheets to skip by individual name:

If sh.name = "whatever" or sh.name = "something" Then
'do nothing
Else
your code
End if

Use a naming convention if you need to skip a lot:

If left(sh.name,4) = "skip" Then
'do nothing
Else
your code
End if

Steve


"ExcelMonkey" wrote

in message
...
I have a For Each Loop that loops through my sheets and
performs certain actions. Is is possible to set the
routine up so that I can exclude certain sheets from the
loop. That is, if I pass the excluded sheets to a
variable or array, can this variable or array be used in
conjuction with the For Each Loop?

For Each sh in Workbook
Logic here that bypasses certain sheets

Next



.



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
Check if Duplicate with Exceptions mjones Excel Worksheet Functions 6 January 18th 10 12:37 PM
Linking worksheets, but exceptions Emily Excel Worksheet Functions 4 August 5th 08 08:06 PM
exceptions in filtering jamie Excel Worksheet Functions 7 June 1st 06 10:38 PM
Merge Worksheets - Exceptions tlozier Excel Discussion (Misc queries) 1 September 17th 05 01:58 AM
InputBoxes Exceptions ianripping[_42_] Excel Programming 3 April 8th 04 09:34 PM


All times are GMT +1. The time now is 03:22 AM.

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

About Us

"It's about Microsoft Excel"