Code to change table name

happyhungarian

Active Member
Joined
Jul 19, 2011
Messages
254
Office Version
  1. 365
Platform
  1. Windows
Hi, I need a code that would take the name of a worksheet and rename the only table that resides on that worksheet to the same name. For example, if I change the name of a worksheet to "Today" the table on that worksheet would also now be named "Today".
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
How do you plan to change the sheet name?
Manually or by using code.

If by code show me the script you have to change the sheet name.
 
Upvote 0
It's part of a code. The sheet name is actually only changed upon creation of the sheet itself. The creation happens through this code as well

Sub CreateAndNameWorksheets()
Dim c As Range

Application.ScreenUpdating = False
For Each c In Sheets("Start").Range("b17:b19")
Sheets("blank").Copy After:=Sheets(Sheets.Count)
With c
ActiveSheet.Name = .Value
.Parent.Hyperlinks.Add Anchor:=c, Address:="", SubAddress:= _
"'" & .Text & "'!A1", TextToDisplay:=.Text
End With
Next c
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
This worked for me...

Code:
Sub Macro1()
Dim Ans As String
Ans = Application.InputBox("Enter New Sheet and Table Name.")
    With ActiveSheet
        .Name = Ans
        .ListObjects(1).Name = Ans
    End With
End Sub
 
Last edited:
Upvote 0
Here is a example:

Maybe you can incorporate this into your script:

Code:
Sub Table_Name()
'Modified 3/28/2019 5:53:38 PM  EDT
ActiveSheet.ListObjects(1).Name = ActiveSheet.Name
End Sub
 
Upvote 0
It worked in a test case! Let's see if I can get it to work along with the bigger script! Thank you!
 
Upvote 0
Assuming when said worked in a test you were referring to my script.
Your script should look like this:
Code:
Sub My_Script()
'Modified 3/28/2019 6:14:25 PM  EDT
Dim c As Range
Application.ScreenUpdating = False
For Each c In Sheets("Start").Range("b17:b19")
Sheets("blank").Copy After:=Sheets(Sheets.Count)
With c
ActiveSheet.Name = .Value
.Parent.Hyperlinks.Add Anchor:=c, Address:="", SubAddress:= _
"'" & .Text & "'!A1", TextToDisplay:=.Text
ActiveSheet.ListObjects(1).Name = ActiveSheet.Name
End With
Next c
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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