Name a sheet from a cell, with error checking

beezlebob999

New Member
Joined
Oct 13, 2015
Messages
1
I am trying to get my sheets to name themselves from a cell within the sheet. I have tried several codes found on this and other forums but the best I have managed is to get it to do it once then come up with errors when it works with a macro I made to add data from another sheet and create a blank copy of the destination worksheet. Hope this makes sense, I would be really grateful for any help people could give. My understanding of VB is basic so please give idiots guides. thanks
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
I am trying to get my sheets to name themselves from a cell within the sheet. I have tried several codes found on this and other forums but the best I have managed is to get it to do it once then come up with errors when it works with a macro I made to add data from another sheet and create a blank copy of the destination worksheet. Hope this makes sense, I would be really grateful for any help people could give. My understanding of VB is basic so please give idiots guides. thanks
Hi beezlebob999, welcome to the boards.

Below is some modified code I found online a while ago which should do what you need. It just needs to be added to a standard VBA module in your workbook then applied to a button to run it.

Rich (BB code):
Sub Rename_Tabs()
' Defines ws as Worksheet
Dim ws As Worksheet
' For each tab in your workbook...
For Each ws In Worksheets
' If an error occurs, continue...
    On Error Resume Next
' If the length of value in cell A1 is greater than 0 then...
    If Len(ws.Range("A1")) > 0 Then
' Rename tab to the value of A1, replacing illegal characters to reduce errors
        ws.Name = Replace(ws.Range("A1").Value, "/", "-")
    End If
    On Error GoTo 0
' If the tab was not renamed...
    If ws.Name <> Replace(ws.Range("A1").Value, "/", "-") Then
' Display messagebox containing message below
        MsgBox ws.Name & " Was Not renamed, the suggested name was invalid"
    End If
Next
End Sub

You can replace the bold red A1 cell reference with whichever cell contains your desired name for renaming to.

I hope this helps.
 
Upvote 0

Forum statistics

Threads
1,216,105
Messages
6,128,861
Members
449,472
Latest member
ebc9

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