I have, on a weekly basis, a workbook having 60+ worksheets with each sheet named page1, page2, etc.
I am renaming each sheet with the following code based on the contents of cell C5 in each sheet. The contents of cell C5 is a user name which should not be duplicated or changed on the worksheet name.
At times, the weekly workbook download contains another sheet with the same username in cell C5 and the code errors when attempting to rename a sheet with a sheet name that already exists.
Is there VBA code that can check in advance, each worksheet, for a duplicate username in cell C5 to warn the user there is a duplicate username in the sheets before running the following code?
Thanks
I am renaming each sheet with the following code based on the contents of cell C5 in each sheet. The contents of cell C5 is a user name which should not be duplicated or changed on the worksheet name.
At times, the weekly workbook download contains another sheet with the same username in cell C5 and the code errors when attempting to rename a sheet with a sheet name that already exists.
Is there VBA code that can check in advance, each worksheet, for a duplicate username in cell C5 to warn the user there is a duplicate username in the sheets before running the following code?
Thanks
Code:
Sub RenameSheets()'/////////////////////////////////////
' Renames each sheet based on cell "C5"
'/////////////////////////////////////
Dim Wks As Worksheet
For Each Wks In ThisWorkbook.Worksheets
If Wks.Name <> "Combined" And Wks.Name <> "employees" Then
Wks.Activate
ActiveSheet.Name = ActiveSheet.Range("C5").Value
End If
Next Wks
End Sub