Forum Discussion

rbellman's avatar
rbellman
Copper Contributor
Nov 12, 2025

Worksheet tabs to include date from a cell

Hello ,

I have a worksheet with four tabs.  Cell H1 in both tabs 1 and three contains a date.  I would like to include that date in the tab name in the following format: for Tab 1 "AR - as of (the date in H1)" and for Tab 3 "AP - as of (the date in H1)".  The dates in the tabs would update whenever the date in cell H1 is updated.  I am using Microsoft 365 Apps for Enterprise, version 2510, Build 19328.20178.  Thank you for your assistance.

8 Replies

  • VBasic2008's avatar
    VBasic2008
    Brass Contributor

    A Worksheet Change: Rename Sheet

    The Worksheet Change event is triggered when you 'manually' change a cell. This includes the following: 
     - After entering edit mode, i.e., using F2 or double-clicking a cell to modify it, but only after confirmation (pressing Enter). This doesn't necessarily mean the value was modified. Also, if you exit edit mode with the ESC key, the event is not triggered.
     - After cut/copy-pasting.
     - After writing to cells using VBA.
    In your particular case, the event will only trigger when you change the value in Sheet1, since Sheet3 has a formula that will not trigger the event.
    Therefore, you need to use the code only for Sheet1 and update both sheet names when this change happens.

    Private Sub Worksheet_Change(ByVal Target As Range)
        
        Dim targetCell As Range: Set targetCell = Me.Range("H1")
        If Intersect(targetCell, Target) Is Nothing Then Exit Sub
        
        Dim sDate As String: sDate = Format(targetCell.Value, "mmm-dd-yyyy")
        
        Me.Name = "AR - as of " & sDate
        Sheet3.Name = "AP - as of " & sDate
    
    End Sub

     

  • rbellman's avatar
    rbellman
    Copper Contributor

    Thank you!!  There is one minor issue; cell H1 on tab 3 is linked to cell H1 on tab 1, so when I update the date in H1 on tab 1, cell H1 on tab 3 also updates.  When the date changes in H1 on tab 1, the date in the tab name updates as it should, but the tab name on tab 3 does NOT update.  I would like the tab names on both tabs 1 and 3 to update when I change the date in cell H1 on tab 1.  Thank you for your assistance.    

    • SnowMan55's avatar
      SnowMan55
      Bronze Contributor

      Assuming that your "linked to cell H1 on tab 1" means that H1 on the user-input worksheet is referenced in an Excel formula on another tab, yes, that can be handled, in one of at least two ways.

      I will try attaching a workbook (built from Lorenzo's starting work).  The forum software may or may not accept it.

      Edit: That did not succeed, so here's the workbook on OneDrive: 2026-01-06 RB AutoRenameWorksheet.xlsm

  • Olufemi7's avatar
    Olufemi7
    Iron Contributor

    You can do this with a simple VBA macro, since sheet names can’t be linked directly to cells. Add this code to the relevant sheets in the VBA editor (Alt+F11):

    Private Sub Worksheet_Change(ByVal Target As Range)
        If Not Intersect(Target, Me.Range("H1")) Is Nothing Then
            Dim dt As String
            dt = Format(Me.Range("H1").Value, "dd-mmm-yyyy")
            
            Select Case Me.CodeName
                Case "Sheet1"   ' adjust to your sheet code name
                    Me.Name = "AR - as of " & dt
                Case "Sheet3"
                    Me.Name = "AP - as of " & dt
            End Select
        End If
    End Sub


    Whenever H1 changes, the tab name updates automatically.

    https://learn.microsoft.com/en-us/office/vba/excel/concepts/workbooks-and-worksheets/name-a-worksheet-by-using-a-cell-value

    • rbellman's avatar
      rbellman
      Copper Contributor

      Thank you - this is very close to what I am looking for.  Cell H1 on tab 3 is linked to cell H1 on tab 1, so H1 on tab 3 updates automatically when I update the date in H1 on tab 1.  Unfortunately, the date in the tab name on tab 3 doesn't update when cell H1 on tab 3 updates.  Does the code need to be modified a bit to accomplish this?  Thank you in advance.

    • rbellman's avatar
      rbellman
      Copper Contributor

      I thought would be the case.  Do you know what the VBA coding would be?  Thank you!

Resources