I have renamed worksheets according to a cell value in the same worksheet, but now I need to rename the worksheet according to a cell value in another worksheet.
Here is the code I tried:
I have pasted that code into the worksheet that needs to be renamed, but it doesn't work. I have also tried:
I like the first one because it checks for a blank value. There will be blank values depending on how many worksheets each teacher needs, so it will just rename the ones that have values filled in. Each worksheet will have the code referencing to a different cell on the Set-Up Page worksheet.
Here is the code I tried:
Code:
Private Sub Worksheet_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Sheets("Set-Up Page").Range("B2").Value <> "" Then
'rename the worksheet to the contents of cell B2
Sh.Name = Sheets("Set-up Page").Range("B2").Value
End If
End Sub
I have pasted that code into the worksheet that needs to be renamed, but it doesn't work. I have also tried:
Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Address = Sheets("Set-up Page").Range("B2") Then Sh.Name = Target
End Sub
I like the first one because it checks for a blank value. There will be blank values depending on how many worksheets each teacher needs, so it will just rename the ones that have values filled in. Each worksheet will have the code referencing to a different cell on the Set-Up Page worksheet.