シート名が好きなシートを削除するにはどうすればよいですか
Left(SheetExists.Name, 16) = "Mgt Report as at"
試した:
Sheets(Left(SheetExists.Name, 16) = "Mgt Report as at").Delete
このようなもの(テストされていません):
For Each s in ActiveWorkbook.Sheets
If Left(s.Name, 16) = "Mgt Report as at" Then
s.Delete
End If
Next s
LIKE
質問のタイトルで述べたように使用する別の方法。
また、このようなシナリオでは、シートを削除するときに注意する必要があります。以下のコードのコメントを参照してください。
Option Explicit
Sub Sample()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Sheets
If ws.Name Like "Mgt Report as at" & "*" Then
'~~> This check is required to ensure that you don't get an error
'~~> if there is only one sheet left and it matches the delete criteria
If ThisWorkbook.Sheets.Count = 1 Then
MsgBox "There is only one sheet left and you cannot delete it"
Else
'~~> This is required to supress the dialog box which excel shows
'~~> When you delete a sheet. Remove it if you want to see the
'~~~> Dialog Box
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
End If
End If
Next
End Sub