按表单代码名称循环跳过多个表单

我有这个代码循环我的工作簿中的所有工作表,并需要跳过一些将被隐藏在我的工作簿中的工作表的代号

这是即时通讯使用的代码。

Dim WS As Worksheet For Each WS In Worksheets 'Skips sheets below example Skip .sheetscodename, .sheetscodename2, and so on 'Insert code to be looped here Set Rng = WS.Range("C7", WS.Range("C1048576").End(xlUp)) For Each cel In Rng If cel.Value = "0" Then cel.EntireRow.Hidden = True End If Next cel 'Next sheet Next WS 

一种方法是创build一个所有要跳过的名称的string,然后使用InStr():

 Dim WS As Worksheet Dim cel As Range, Rng As Range Dim shts As String shts = ("sheetscodename,sheetscodename2,...") For Each WS In Worksheets If InStr(1, shts & ",", WS.CodeName & ",", vbTextCompare) = 0 Then 'Insert code to be looped here Set Rng = WS.Range("C7", WS.Range("C1048576").End(xlUp)) For Each cel In Rng If cel.Value = "0" Then cel.EntireRow.Hidden = True End If Next cel End If 'Next sheet Next WS