Changing Worksheet Name based on formula

BigViking

New Member
Joined
Jul 8, 2016
Messages
3
I am creating an annual calendar with a tab for each month as well as a parameter tab. Users can select the start month in the parameter tab and all the other tabs will update automatically. The only thing that I cannot get to change automatically is the tab names. I have found various codes out there that allow the tab names to be changed based on a cell value, however, when that cell contains a formula (to show the relevant month) it will not rename the tab. Can anyone assist me with this? Thank you
 

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.
What is the formula, presumably on the 'parameter' tab, and what do you want the tab names to change from and to?
 
Upvote 0
What is the formula, presumably on the 'parameter' tab, and what do you want the tab names to change from and to?
Each worksheet has a field =TEXT(B12,"mmmm") which simply pulls the month from a separate date field. I want this month name to be the tab name
 
Upvote 0
from a separate date field
And where is the "separate date field"? What I'm trying to determine is whether a Worksheet Change or Calculate event could be used to automatically change all the tab names. You said in your initial post:
Users can select the start month in the parameter tab
How is this done?
 
Upvote 0
Also, where is the TEXT formula located on each sheet?
 
Upvote 0
While I'm waiting for your responses, here's a demo of what's possible with worksheet change event code. For the purpose of the demonstration, it's assumed that your parameters sheet is called "parameters" and that a change in cell A1 of that sheet (manually or by dropdown selection etc.) will trigger the code to run.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.CountLarge = 1 And Not Intersect(Range("A1"), Target) Is Nothing Then
        On Error GoTo Escape
        Application.EnableEvents = False
        Dim ws As Worksheet
        For Each ws In ThisWorkbook.Worksheets
            If ws.Name <> "parameters" Then
                ws.Name = Format(ws.Range("B12").Value, "MMM")
            End If
        Next ws
    End If
Continue:
    Application.EnableEvents = True
    Exit Sub
Escape:
    MsgBox "Error " & Err.Number & ": " & Err.Description
    Resume Continue
End Sub
 
Upvote 0
Couple of tweaks on the previous code - but also runs when a change is manually made to cell A1 in your parameters sheet.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.CountLarge = 1 And Not Intersect(Range("A1"), Target) Is Nothing Then
        On Error GoTo Escape
        Application.EnableEvents = False
        Dim ws As Worksheet, s As String, i As Long
        s = Me.Name
        'give the sheets a temporary name
        For Each ws In ThisWorkbook.Worksheets
            If ws.Name <> s Then
                ws.Name = "Temp " & i
                i = i + 1
            End If
        Next ws
        'give the sheets their new name
        For Each ws In ThisWorkbook.Worksheets
            If ws.Name <> s Then
                ws.Name = Format(ws.Range("B12").Value, "MMM")
            End If
        Next ws
    End If
Continue:
    Application.EnableEvents = True
    Exit Sub
Escape:
    MsgBox "Error " & Err.Number & ": " & Err.Description
    Resume Continue
End Sub
 
Upvote 0
Solution
And where is the "separate date field"? What I'm trying to determine is whether a Worksheet Change or Calculate event could be used to automatically change all the tab names. You said in your initial post:

How is this done?
So, the 'Parameters' tab has a drop down list in B6 where you can select the start month. On the other tabs, the =TEXT(B12,"mmmm") formula in W2
Couple of tweaks on the previous code - but also runs when a change is manually made to cell A1 in your parameters sheet.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.CountLarge = 1 And Not Intersect(Range("A1"), Target) Is Nothing Then
        On Error GoTo Escape
        Application.EnableEvents = False
        Dim ws As Worksheet, s As String, i As Long
        s = Me.Name
        'give the sheets a temporary name
        For Each ws In ThisWorkbook.Worksheets
            If ws.Name <> s Then
                ws.Name = "Temp " & i
                i = i + 1
            End If
        Next ws
        'give the sheets their new name
        For Each ws In ThisWorkbook.Worksheets
            If ws.Name <> s Then
                ws.Name = Format(ws.Range("B12").Value, "MMM")
            End If
        Next ws
    End If
Continue:
    Application.EnableEvents = True
    Exit Sub
Escape:
    MsgBox "Error " & Err.Number & ": " & Err.Description
    Resume Continue
End Sub
Oh wow! This worked! Thank you so much!! You have no idea how long I have been trying to figure this out :^)
 
Upvote 0

Forum statistics

Threads
1,215,091
Messages
6,123,062
Members
449,089
Latest member
ikke

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