Dynamic Table Names - Possible?

ramohse

Board Regular
Joined
Sep 30, 2013
Messages
50
Hello


I am wondering if there is a clever way to automatically make a table's name the same as whatever the name of the sheet is on which it resides.

Basically I want to create a table on a sheet named S01W01, then ctrl+copy that sheet and name the new, copied sheet S01W02, and have the table on the first sheet be named "S01W01" and the table on the second named "S01W02" (for dynamic dashboard purposes). I could use VBA to accomplish this (maybe on a sheet-copy event or something?), but I plan on handing this file off to people who are not familiar with VBA and would prefer they be able to copy sheets at will and have everything work.

Can this happen? I am using Excel 2010.

Thank you!
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
You could try adding this to ThisWorkbook code module

Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)Const TABLE_NAME_BASE As String = "S01W"


    With ThisWorkbook


        On Error Resume Next
        Sh.ListObjects(1).Name = TABLE_NAME_BASE & Format(Sh.Index, "00")
    End With
End Sub
 
Upvote 0
Thank you! For some reason it doesn't like the Sub title. It is red in the VBA editor, and the names haven't changed...
 
Upvote 0
haha nevermind, I got it. Works perfectly! Thank you very much! And that was exceedingly clever...
 
Upvote 0

Forum statistics

Threads
1,203,453
Messages
6,055,530
Members
444,794
Latest member
HSAL

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