Hi Everyone,
Is there a way to enter a word in an inputbox and have a macro delete all worksheets containing that word?
I have the macro below but I don't know how to incorporate the InputBox function to ask the user to enter the criteria for deletion.
For example, I should be able to enter Sales, and the macro will delete worksheet sales, sale2, and salesreport from my workbook...
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
Bookmarks