VBA to make Sheet Name = Cell Value

dpc1987

New Member
Joined
Jun 25, 2013
Messages
15
Is there a vba code to make a sheet name equal a cell value without it being a Private Sub Workbook Change? The reason it can't be private, is because I am taking a summary sheet of a configured part number and copying the sheet within the same workbook. So making it private would cause the first summary sheet to be "ABC" and the copy as "ABC(2)". I already have code to copy the sheet, so I'm looking to add to the code to make the new sheet equal a cell value.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Hi,

This code will rename the active sheet to whatever is in A1 of the worksheet. If the re-name fails because of illegal characters then a warning is given.


Code:
Sub rename_Sheet()
Dim OldName As String
OldName = ActiveSheet.Name
On Error Resume Next
ActiveSheet.Name = Range("A1").Value
On Error GoTo 0
If OldName = ActiveSheet.Name Then
    MsgBox "Worksheet not renamed, Illegal name or no data available"
End If
End Sub
 
Upvote 0
I didn't follow the relevance to the Private Sub Workbook Change comments.

This example renames the sheet using the A1 value
Code:
ActiveSheet.Name = ActiveSheet.Range("A1").Value
 
Upvote 0
Is there a vba code to make a sheet name equal a cell value without it being a Private Sub Workbook Change? The reason it can't be private, is because I am taking a summary sheet of a configured part number and copying the sheet within the same workbook. So making it private would cause the first summary sheet to be "ABC" and the copy as "ABC(2)". I already have code to copy the sheet, so I'm looking to add to the code to make the new sheet equal a cell value.

If you copy a sheet within the same workbook, Excel automatically adds a numerical suffix in parentheses, based on how many times you copy the same sheet. ie. first copy "ABC(2)", second 'ABC(3)", etc. Same thing if you copy to a different workbook, Excel still gives it a numerical suffix on the original name. But if you have code like:
Code:
Worksheets("ABC").Copy After:=Sheets(Sheets.Count)
Then the copied sheet with the suffix will be the active sheet so to name it using, eg. cell A2, then
Code:
ActiveSheet.Name = ActiveSheet.Range("A2").Value
would use the text in cell A2 of the active sheet as the sheet name.
 
Upvote 0
Hi Mike
I have the same problem so I used your code. But it works only on one worksheet. How do I make it work on all worksheets in the workbook. The neme in all worksheets is in the same cell (F4) of each worksheet.
 
Upvote 0

Forum statistics

Threads
1,214,998
Messages
6,122,638
Members
449,093
Latest member
Ahmad123098

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