Hi,
I need to macro to check all sheets within my work book and if the sheet name is matched in a named range("specific activity" located only on sheet "all lists") I want to delete the sheet/s when their name is matched in this range.
I've been searching and found different examples but I cannot get the to work. I don't really understand the application.match. I think the below just refers to a range on the active sheet. I want it to always check the names range ("specific_activity) which is stored on sheet("lists")
My coding is limited. Appreciate your help
Deletenotinlist()
'Updateby Extendoffice 20160930
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("A2:A6"), 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 "Not find the sheets to be seleted", vbInformation, "Kutools for Excel"
Else
MsgBox "Have deleted" & cnt & "worksheets"
End If
End Sub
I need to macro to check all sheets within my work book and if the sheet name is matched in a named range("specific activity" located only on sheet "all lists") I want to delete the sheet/s when their name is matched in this range.
I've been searching and found different examples but I cannot get the to work. I don't really understand the application.match. I think the below just refers to a range on the active sheet. I want it to always check the names range ("specific_activity) which is stored on sheet("lists")
My coding is limited. Appreciate your help
Deletenotinlist()
'Updateby Extendoffice 20160930
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("A2:A6"), 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 "Not find the sheets to be seleted", vbInformation, "Kutools for Excel"
Else
MsgBox "Have deleted" & cnt & "worksheets"
End If
End Sub