ワークブックで実行されるマクロからこれらのシートを除外するにはどうすればよいですか? シートの除外に慣れていないため、コードを完成させるのに苦労しています。
私がこれまでに持っているもの:
Dim sh As Worksheet
If sh.Name <> "Apples" And sh.Name <> "Oranges" And ws.Name <> "Grapes" Then
まず、除外するすべてのシートの名前を表す変数を作成します。
Const excludeSheets as String = "Apples,Oranges,Grapes,David,Hector,Sheet1"
次に、次のようなことができます。
If IsError(Application.Match(sh.Name, Split(excludeSheets,","))) Then
'code will manipulate the sheets which are not found in the array
MsgBox sh.Name & " is not excluded!"
Else:
Msgbox sh.Name & " is excluded!"
End If
アップデート
sh
あなたの新しいコードを予想して、変数を割り当てていないと思います。
ループ構造でこれを行うことができます:
Sub ShowMeTheSheets()
Dim sh as Worksheet
Const excludeSheets as String = "Apples,Oranges,Grapes,David,Hector,Sheet1"
For each sh in ThisWorkbook.Worksheets 'Assigns a Worksheet Object to the sh Variable.
If IsError(Application.Match(sh.Name, Split(excludeSheets,","))) Then
'code will manipulate the sheets which are not found in the array
MsgBox sh.Name & " is not excluded!"
Else:
Msgbox sh.Name & " is excluded!"
End If
Next
End Sub