Hi,
I have this code. instead of deleting sheets which don't match text in A8:A12 I would like to delete sheets which don't contain text in A8:A12.
Sub DeleteNotInList()
Dim i As Long
Dim cnt As Long
Dim xWb, actWs As Worksheet
Set actWs = ThisWorkbook.ActiveSheet
cnt = 0
Application.DisplayAlerts = False
For i = Sheets.Count To 1 Step -1
If Not ThisWorkbook.Sheets(i) Is actWs Then
xWb = Application.Match(Sheets(i).Name, actWs.Range("A8:A12"), 0)
If IsError(xWb) Then
ThisWorkbook.Sheets(i).Delete
cnt = cnt + 1
End If
End If
Next
Application.DisplayAlerts = True
If cnt = 0 Then
MsgBox "Did not find the sheets to be seleted", vbInformation, "Error"
Else
MsgBox "Have deleted" & cnt & "worksheets"
End If
End Sub
Regards,
GC
Bookmarks