So this code needs to look at a list on the first worksheet and create new worksheets based on that list, but only the new values. It works some of the time, but if there are no values in the list then I get an error message regarding the last If statement. Any help would be greatly appreciated!
Here is the code so far:
'Declare Variables
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 = c.Value 'this is where the error message pops up
End If
Next c2
End Sub
I tried the new code but I am still getting an error message when there are no items on the list.
Bookmarks