Hi everyone, I am having trouble with my VBA code in one particular instance. I have this code that will delete any worksheet that is not specified on a list in the first workbook, and everything works fine except for when the list is empty. When the list is empty, I need all of the worksheets to be deleted except for the one with the list.

Here is the code:

Dim bottomA As Long
Dim c2 As Range
Dim ws2 As Worksheet

'Set Range

bottomA = Range("A" & Rows.Count).End(xlUp).Row

'Loop through each value in range and create worksheet
For Each c2 In Range("A2:A" & bottomA)
Set ws2 = Nothing
On Error Resume Next
Set ws2 = Worksheets(c2.Value)
On Error GoTo 0
'set the name of the worksheet

If ws2 Is Nothing Then
Worksheets.Add(After:=Sheets(Sheets.Count)).Name = c2.Value 'this is where the error message pops up
End If
Next c2

When it runs when there are no items on the list, it deletes all of the worksheets and keeps the one with the list, but it creates a new one and an error message pops up. Any help would be greatly appreciated!