Getting a TAB name to appear in a cell

damian_r

Active Member
Joined
May 4, 2004
Messages
389
Howdo,
I have a workbook with several sheets, each sheet having a different name.

The front sheet is a summary sheet and in some of the cells I have manually typed in a header which is the name of the tab that the values below it come from.

When somebody renames the sheet (which we need to do from time to time) the Header no longer refers to the correct sheet.....

Is there a way that I can get the cell to automatically show a name of a tab so that when the tab name changes, the cell name text changes?
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Assuming you want the sheet name entered into row(1)
And sheet(1) name will be in Range("A1") and sheet(2).Name will be in Range("B1")

Put this script in your Master Sheet

Now any time that sheet is activated the correct sheet names will be entered.
There is no way this can just happen when any sheet name is changed. But this will update all the names every time you activate your Master Sheet.

This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on the sheet tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window


Code:
Private Sub Worksheet_Activate()
Dim i As Long
For i = 1 To Sheets.Count
Cells(1, i).Value = Sheets(i).Name
Next
End Sub
 
Upvote 0
Put this into a Module:

Code:
Function TabName()
  TabName = ActiveSheet.Name
End Function

Then reference it in a cell by using this formula:

Code:
=TabName()

I hope this helps!
 
Upvote 0
Press Alt-F11 and copy and paste my code in there.

In a cell enter the formula: =TabName()

Let us know how you get on!
 
Upvote 0
Is there a way that I can get the cell to automatically show a name of a tab so that when the tab name changes, the cell name text changes?

Hi, here is a formula you can try where Sheet1 is the current name of the worksheet.

=TRIM(RIGHT(SUBSTITUTE(CELL("filename",'Sheet1'!A1),"]",REPT(" ",50)),50))
 
Upvote 0

Forum statistics

Threads
1,221,959
Messages
6,163,101
Members
451,814
Latest member
P_Wood

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