Renaming specific excel sheets using macro and cell value

jr0124

New Member
Joined
Dec 28, 2016
Messages
16
Hello,

I am looking for some help, I have a spreadsheet that has 8 tabs, 5 of those I was looking to rename based on cell B14 in that sheet. I was trying something like this but I can't figure out how to have it select the correct B14 value and change only those tabs I need to rename. The current sheets are numbers, 1, 2, 3, 4 and 5.

Any ideas on how to adjust to accomplish what I am looking to do?

Sub tabname()
Dim ws As Worksheet
For Each ws In Worksheets
On Error Resume Next
If Len(ws.Range("B14")) >0 Then
ws.Name = ws.Range("B14").Value
End If
On Error Goto 0
If ws.Name <> ws.Range("B14").Value Then
Msgbox ws.Name & " Was Not renamed, the suggested name was invalid"
End If
Next
End Sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
If by
The current sheets are numbers, 1, 2, 3, 4 and 5.
You mean the sheet index, try
Code:
Sub tabname()
    Dim Cnt As Long
    
    For Cnt = 1 To 5
        With Sheets(Cnt)
            If Len(.Range("B14")) > 0 Then
                On Error Resume Next
                .Name = .Range("B14").Value
                On Error GoTo 0
            End If
            If .Name <> .Range("B14").Value Then MsgBox .Name & " Was Not renamed, the suggested name was invalid"
        End With
    Next Cnt
End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

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