I want to add a loop that create worksheets with the same name on the list, if the workbook does not have the same named worksheets in a list.
How would I add it on this code?
Can anyone do it..?
Sub DeleteSheet()
Dim WS As Worksheet, SheetsToKeep As String
Const SheetNameWithList As String = "List"
''''First worksheet has the list, and Cell A1 is the title of list
SheetsToKeep = "/" & SheetNameWithList & "/" & Join(Application.Transpose( _
Range("A2", Cells(Rows.Count, "A").End(xlUp)).Value), "/") & "/"
Application.DisplayAlerts = False
On Error Resume Next
For Each WS In ThisWorkbook.Worksheets
If InStr(SheetsToKeep, "/" & WS.Name & "/") = 0 Then WS.Delete
Next
On Error GoTo 0
Application.DisplayAlerts = True
End Sub
How would I add it on this code?
Can anyone do it..?
Sub DeleteSheet()
Dim WS As Worksheet, SheetsToKeep As String
Const SheetNameWithList As String = "List"
''''First worksheet has the list, and Cell A1 is the title of list
SheetsToKeep = "/" & SheetNameWithList & "/" & Join(Application.Transpose( _
Range("A2", Cells(Rows.Count, "A").End(xlUp)).Value), "/") & "/"
Application.DisplayAlerts = False
On Error Resume Next
For Each WS In ThisWorkbook.Worksheets
If InStr(SheetsToKeep, "/" & WS.Name & "/") = 0 Then WS.Delete
Next
On Error GoTo 0
Application.DisplayAlerts = True
End Sub