Hi guys,

I have a Workbook that creates a new sheet for each member of staff in a list, however I want it to skip any member of staff for which a sheet already exists (avoiding using an error handler).

I have the below, but it seems to try and create sheet even if it exists. Any ideas? Thanks!


Function WorksheetExists(WSName As String) As Boolean

On Error Resume Next

WorksheetsExists = Worksheets(WSName).Name = WSName

On Error GoTo 0

End Function

Sub CreateTimesheets()
    
    Dim SheetName As String
    Dim NumberofStaff As Long
     
    Dim i As Integer

Application.ScreenUpdating = False

Worksheets("Staff").Select
NumberofStaff = Application.CountA(Range("A:A")) - 3

     For i = 1 To NumberofStaff
            
            SheetName = "" & Worksheets("Staff").Cells(i + 3, "A")
            
            If Not WorksheetExists(SheetName) Then
                Sheets("Timesheet Template").Copy After:=Sheets(Sheets.Count)
                Sheets(Sheets.Count).Name = SheetName
                Cells(1, 3) = SheetName
                Cells(1, 1) = "VALID"
            End If
    
    Next i

End Sub