Hi Everyone,
the following code gives all worksheets in a workbook the name of the string found in cell A1.
But I have the problem that I have sheets which have only one word. Then the script does not work anymore.
Also I would like to have the complete content of cell A1 as sheet name no matter what is in it.
Maybe you can help me to adjust the code to use all characters in cell A1 as sheet names of the respective sheet.
Here is the Code:
Sub RenameWorksheet_Content_A1_2_Words() Dim WS As Worksheet Dim shtName Dim newName As String Dim i As Integer For Each WS In Worksheets With WS If Trim(.Range("A1")) <> "" Then shtName = Split(Trim(.Range("A1")), " ") newName = shtName(0) & " " & shtName(1) On Error GoTo ws_name_error .Name = newName GoTo done repeat: .Name = newName & i GoTo done ws_name_error: i = i + 1 Resume repeat End If End With On Error GoTo 0 done: Next End Sub
Bookmarks