VBA Macro Help - Rename sheet tabs based on cell text value

Anonymous
2025-01-06T22:51:13+00:00

Hi everyone,

I need some macro assistance.

I have the following code:

Sub RenameSheets()

For Each ws In Sheets

ws.Name = ws.Range("A1") 

Next ws

End Sub

The idea is that I want the sheet tab name to change based on the value in A1. I have 40 tabs.

My problem is that have to manually run this code every time. How do I change the value in A1 and the sheet name changes without the manual process?

Thanks,

Chris

Microsoft 365 and Office | Excel | Other | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

7 answers

Sort by: Most helpful
  1. HansV 462.4K Reputation points MVP Volunteer Moderator
    2025-01-06T23:02:49+00:00

    In the Visual Basic Editor, double-click ThisWorkbook under Microsoft Excel Objects in the Project Explorer pane on the left hand side.

    Copy the following code into the ThisWorkbook module:

    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
        If Not Intersect(Sh.Range("A1"), Target) Is Nothing Then
            On Error Resume Next
            Sh.Name = Sh.Range("A1").Value
        End If
    End Sub
    
    0 comments No comments
  2. Anonymous
    2025-01-07T14:40:03+00:00

    Thanks Hans. I am still running into some issues with the code. I've followed your instructions, and I get this error:

    It won't let me run the code.

    Thanks,

    Chris

    0 comments No comments
  3. HansV 462.4K Reputation points MVP Volunteer Moderator
    2025-01-07T15:28:24+00:00

    The Workbook_SheetChange procedure is not a macro that you can run.

    It is a so-called event procedure that will run fully automatically when you enter or edit a value in cell A1 on any of the worksheets.

    Try it: select any sheet, and enter a name in cell A1 (it should not coincide with any of the existing sheet names).

    After pressing Tab or Enter, you should see the sheet name changing automatically.

    0 comments No comments
  4. Anonymous
    2025-01-07T15:54:19+00:00

    Thanks! It worked. Now here is the trickier part of the question. Cell A1 is based on a formula. Is there a way to make that work out.

    For example, the formula is simple =Master!A8. I noticed when I change the cell A8 on the Master tab, it'll change A1 on the correct sheet, but the tab name won't change.

    0 comments No comments
  5. Anonymous
    2025-01-07T16:11:43+00:00

    I guess I should explain what I am trying to do.

    I have one master sheet tab.

    The workbook has 40 sheets.

    Each sheet is linked to a cell on the Master tab.

    All names appear on their respective sheets in Cell A1.

    Cell A1 is linked to a cell on the Master tab.

    When I change the name, I want it to change the name on the sheet and the sheet tab.

    I thought I could do it by adding a formula and the macro would read the text and not be messed up by the formula.

    As of right now, it will change the name of the sheet, but not the sheet tab.

    Probably easiest explanation is that cell A1 is based on a formula and I need excel to read the text and make that sheet name.

    0 comments No comments