Saving as Macro Template breaks link from cell to tab name

dianamruelas

New Member
Joined
Sep 28, 2015
Messages
44
Office Version
  1. 365
Platform
  1. Windows
Hello,
I have the following formula in Cell A1 of every tab that will make the cell contain the name of the tab. There are several Macros in the workbook. When I try to save as a Macro Template, the cells no longer have the name of the tab. They are all replaced with #VALUE!, on every sheet. Please advise.

=MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,256)
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Code:
'=sheetname(A1)
Function SheetName(aRange As Range) As String
  Application.Volatile (True)
  SheetName = aRange.Parent.Name
End Function
 
Upvote 0
Thank you so much. Could you please be specific where I put this? ...as a formula in a cell? VBA?
 
Upvote 0
I designed as a UDF. Copy and paste the code to a Module. Use it as a UDF in any cell as commented.
 
Upvote 0
Any ideas how I can do this without a Macro? I liked the formula, especially since it updated automatically when the name of the tab was changed. I'm just not sure why I get the #VALUE! error once I save the document as a template.
 
Upvote 0
Obviously, a file based on the template would not have a file path until it is saved. So, you will have to save it before a formula like that will return the result that you expect.
 
Upvote 0
If you want all your sheets to always have the sheet name in cells "A1" I would suggest this.

Install this code:

Right-click on any sheet tab
Select View Code from the pop-up context menu
Look on the top left and double click on "This Workbook"
Paste this code in the VBA edit window
Now every time you activate your sheet the sheet name will be paced in range "A1"

Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Cells(1, 1).Value = ActiveSheet.Name
End Sub
This will also happen every time you create a new sheet
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,334
Members
452,636
Latest member
laura12345

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