ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   For Each Next (https://www.excelbanter.com/excel-programming/307753-each-next.html)

greg

For Each Next
 
Hi,

I have 12 sheets and need to run For Each - Next loop only
on 9 of them.
How would I exclude 3 other sheets?

I can't amend sheet names ( or sheet code names).


TIA,

Greg


Vasant Nanavati

For Each Next
 
Dim ws As Worksheet
For Each ws In Worksheets
If ws.Name < "whatever" And ws.Name < "whateverelse" _
And ws.Name < "whateveragain" Then
'run your procedure
End If
Next

--

Vasant


"Greg" wrote in message
...
Hi,

I have 12 sheets and need to run For Each - Next loop only
on 9 of them.
How would I exclude 3 other sheets?

I can't amend sheet names ( or sheet code names).


TIA,

Greg




Don Guillett[_4_]

For Each Next
 
for each ws in worksheets
if ws.name<"name1" and ws.name<"name2" etc

--
Don Guillett
SalesAid Software

"Greg" wrote in message
...
Hi,

I have 12 sheets and need to run For Each - Next loop only
on 9 of them.
How would I exclude 3 other sheets?

I can't amend sheet names ( or sheet code names).


TIA,

Greg




greg

For Each Next
 
Many thanks to Vasant and Don.

This is exactly what I needed.



-----Original Message-----
Dim ws As Worksheet
For Each ws In Worksheets
If ws.Name < "whatever" And ws.Name

< "whateverelse" _
And ws.Name < "whateveragain" Then
'run your procedure
End If
Next

--

Vasant


"Greg" wrote in

message
...
Hi,

I have 12 sheets and need to run For Each - Next loop

only
on 9 of them.
How would I exclude 3 other sheets?

I can't amend sheet names ( or sheet code names).


TIA,

Greg



.


Glenn_Ray[_3_]

For Each Next
 
You could also use casing. Would be easier to modify if new sheets ar
excluded.


Sub SheetMod()
Dim ws As Worksheet
For Each ws In Worksheets
Select Case ws.Name
Case "--1st sheet to exclude--"
'Null
Case "--2nd sheet to exclude--"
'Null
Case "--3rd sheet to exclude--"
'Null
Case Else
*** code to modify other sheets ***
End Select
Next

End Su

--
Message posted from http://www.ExcelForum.com


Don Guillett[_4_]

For Each Next
 
glad to help

--
Don Guillett
SalesAid Software

"Greg" wrote in message
...
Many thanks to Vasant and Don.

This is exactly what I needed.



-----Original Message-----
Dim ws As Worksheet
For Each ws In Worksheets
If ws.Name < "whatever" And ws.Name

< "whateverelse" _
And ws.Name < "whateveragain" Then
'run your procedure
End If
Next

--

Vasant


"Greg" wrote in

message
...
Hi,

I have 12 sheets and need to run For Each - Next loop

only
on 9 of them.
How would I exclude 3 other sheets?

I can't amend sheet names ( or sheet code names).


TIA,

Greg



.





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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com