Hi.

I have the following code I got from this forum. It renames a sheet based on the contents of cell B5. It works fine but when there is a duplicate name in B5 (I have multiple sheets) it errors.
Is there something I can add that will handle duplicate names, e.g. add (1) after the name if it is a duplicate?

Thanks

Ian

Sub RenameTabsHandlingNulls()
' Renames all worksheet tabs with each worksheet's cell B5 contents.
'If cell B5 has no content, then the tab is named as "Default"
    
  For I = 1 To Sheets.Count
    If Worksheets(I).Range("B5").Value <> "" Then
        Sheets(I).Name = Worksheets(I).Range("B5").Value
    Else:
        Sheets(I).Name = "Default (" & I & ")"
    End If
  Next
End Sub