删除表名像
如何删除工作表名称所在的工作表
Left(SheetExists.Name, 16) = "Mgt Report as at"
尝试:
Sheets(Left(SheetExists.Name, 16) = "Mgt Report as at").Delete
像这样(未testing):
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