Rename tabs to cell values

Nuttie10

New Member
Joined
Apr 25, 2011
Messages
4
Good day guys, I'm sure someone will be able to help me.
I'm new to VBA (know nothing) and found a macro i can use to rename my tabs to cell values on each new worksheet, sometimes over a hundred worksheets(time sheets) depending on the amount of guys on site. It works well but i need three other worksheets to stay unchanged.

The code:

Sub RenameFromA1()
Dim Msg As String, i As Integer
For i = 1 To Sheets.Count
If Sheets(i).Range("U17").Value = "" Then
Msg = "Sheet " & i & "(" & Sheets(i).Name & ") has no value in U17. Fix sheet, then rerun."
MsgBox Msg, vbExclamation
Exit Sub
Else
On Error GoTo ErrSheetName
Sheets(i).Name = Sheets(i).Range("U17").Value
On Error GoTo 0
End If
Next i
Exit Sub
ErrSheetName: Msg = "Sheet " & i & "(" & Sheets(i).Name & ") could not be renamed. Check if name already used."
MsgBox Msg, vbExclamation

End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
For the worksheet to stay with their oldnames you can use If not statement.
For example:
Code:
'Assume that the name of the sheet that needs to be unchanged is 'Sheet1
if not Sheets(i).Name = "Sheets1" then
  Sheets(i).Name = Sheets(i).Range("U17").Value
end if
 
Last edited:
Upvote 0
I must be doing something wrong because it doesn't work.
The name of the two worksheets that need to stay unchanged are "Employee List & Timesheet"
 
Upvote 0
Try

Code:
Sub RenameFromA1()
Dim Msg As String, i As Integer
For i = 1 To Sheets.Count
    Select Case Sheets(i).Name
        Case "Employee List", "Timesheet"
            'do nothing
        Case Else
            If Sheets(i).Range("U17").Value = "" Then
                Msg = "Sheet " & i & "(" & Sheets(i).Name & ") has no value in U17. Fix sheet, then rerun."
                MsgBox Msg, vbExclamation
                Exit Sub
            Else
                On Error GoTo ErrSheetName
                Sheets(i).Name = Sheets(i).Range("U17").Value
                On Error GoTo 0
            End If
        End Select
Next i
Exit Sub
ErrSheetName: Msg = "Sheet " & i & "(" & Sheets(i).Name & ") could not be renamed. Check if name already used."
MsgBox Msg, vbExclamation
End Sub
 
Upvote 0
Thanks a MILLION.
I gotta learn how to use VBA.
Can you perhaps recommend any good books or online sites to teach myself VBA,
I have very limited resources.
Thank you very much VoG, your help is greatly appreciated.
 
Upvote 0

Forum statistics

Threads
1,224,516
Messages
6,179,231
Members
452,898
Latest member
Capolavoro009

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top