ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Step through sheets, but exclude one (https://www.excelbanter.com/excel-programming/399672-step-through-sheets-but-exclude-one.html)

CLR

Step through sheets, but exclude one
 
Hi All.........

I use code similar to the following to step through all the sheets in a
workbook and perform a certain task thereon. It works fine, except that I
would like for the sheet named XXXYYYZZZ to be left alone and the
operation(s) NOT performed thereon. How might I exclude just that one sheet,
yet perform all the operations on all the other sheets?

Dim sh As Object
Dim i as long
i = 0
For Each sh In Sheets
i = i + 1
Sheets(i).Select
Call MyTaskCode

next

TIA for suggestions

Vaya con Dios,
Chuck, CABGx3



Chip Pearson

Step through sheets, but exclude one
 
Try something like

Sub AAA()
Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
If StrComp(WS.Name, "XXXXXX", vbTextCompare) < 0 Then
' WS is not the XXXXX worksheet. Do something with WS.
Else
' WS is XXXXX, do nothing.
End If
Next WS
End Sub

--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"CLR" wrote in message
...
Hi All.........

I use code similar to the following to step through all the sheets in a
workbook and perform a certain task thereon. It works fine, except that I
would like for the sheet named XXXYYYZZZ to be left alone and the
operation(s) NOT performed thereon. How might I exclude just that one
sheet,
yet perform all the operations on all the other sheets?

Dim sh As Object
Dim i as long
i = 0
For Each sh In Sheets
i = i + 1
Sheets(i).Select
Call MyTaskCode

next

TIA for suggestions

Vaya con Dios,
Chuck, CABGx3




Gary Brown

Step through sheets, but exclude one
 
If Sheets(i).Name < "XXXYYYZZZ" Then
Call MyTaskCode
End If

--
HTH,
Gary Brown

If this post was helpful to you, please select
''''''''''''''''YES'''''''''''''''' at the bottom of the post.



"CLR" wrote:

Hi All.........

I use code similar to the following to step through all the sheets in a
workbook and perform a certain task thereon. It works fine, except that I
would like for the sheet named XXXYYYZZZ to be left alone and the
operation(s) NOT performed thereon. How might I exclude just that one sheet,
yet perform all the operations on all the other sheets?

Dim sh As Object
Dim i as long
i = 0
For Each sh In Sheets
i = i + 1
Sheets(i).Select
Call MyTaskCode

next

TIA for suggestions

Vaya con Dios,
Chuck, CABGx3



CLR

Step through sheets, but exclude one
 
Thank you kind Sirs.............

My day is done here now but I shall try both suggestions over the
weekend......

Vaya con Dios,
Chuck, CABGx3



"CLR" wrote:

Hi All.........

I use code similar to the following to step through all the sheets in a
workbook and perform a certain task thereon. It works fine, except that I
would like for the sheet named XXXYYYZZZ to be left alone and the
operation(s) NOT performed thereon. How might I exclude just that one sheet,
yet perform all the operations on all the other sheets?

Dim sh As Object
Dim i as long
i = 0
For Each sh In Sheets
i = i + 1
Sheets(i).Select
Call MyTaskCode

next

TIA for suggestions

Vaya con Dios,
Chuck, CABGx3




All times are GMT +1. The time now is 04:41 PM.

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