To delete specific sheet by name
******changes the shName base on name of sheet
Sub Deletebyname()
'Updateby Extendoffice 20160930
Dim shName As String
Dim xName As String
Dim xWs As Worksheet
Dim cnt As Integer
shName = "Sheet"
''ThisWorkbook.ActiveSheet.Name, , , , , 2)
If shName = "" Then Exit Sub
xName = "*" & shName & "*"
' MsgBox xName
Application.DisplayAlerts = False
cnt = 0
For Each xWs In ThisWorkbook.Sheets
If xWs.Name Like xName Then
xWs.delete
cnt = cnt + 1
End If
Next xWs
Application.DisplayAlerts = True
MsgBox "Have deleted" & cnt & "worksheets", vbInformation, "Kutools for Excel"
End Sub
No comments:
Post a Comment