Sub RenameSheets()
Dim ws As Worksheet, x%, y%
x = 1
For y = 1 To Worksheets.Count
For Each ws In Worksheets
On Error Resume Next
ws.Name = ws.[D8] & " - " & ws.[G15]
If Err.Number > 0 Then
ws.Name = "Check " & x
x = x + 1
End If
On Error GoTo 0
Next
Next
End Sub
Hey, how can we apply it for only one worksheet? I applied it by selecting the sheet from objects but still, it applies to the workbook.If the macro renames any of the sheets "Check" followed by a number, it will be because either there is already a sheet with the required name or there is an invalid sheetname character in D8 and/or G15.Code:Sub RenameSheets() Dim ws As Worksheet, x%, y% x = 1 For y = 1 To Worksheets.Count For Each ws In Worksheets On Error Resume Next ws.Name = ws.[D8] & " - " & ws.[G15] If Err.Number > 0 Then ws.Name = "Check " & x x = x + 1 End If On Error GoTo 0 Next Next End Sub
Yeah, the cell is of the same sheet to be renamed. Thanks for replying so quick!Welcome to the Board.
which cell gets the name for the sheet? Is it the same sheet?
thx
FS