Code to change table name

happyhungarian

Board Regular
Joined
Jul 19, 2011
Messages
226
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".
 

Some videos you may like

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
17,252
Office Version
  1. 2013
Platform
  1. Windows
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.
 

happyhungarian

Board Regular
Joined
Jul 19, 2011
Messages
226
Office Version
  1. 365
Platform
  1. Windows
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:

jim may

Well-known Member
Joined
Jul 4, 2004
Messages
7,480
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:

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
17,252
Office Version
  1. 2013
Platform
  1. Windows

ADVERTISEMENT

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
 

happyhungarian

Board Regular
Joined
Jul 19, 2011
Messages
226
Office Version
  1. 365
Platform
  1. Windows
It worked in a test case! Let's see if I can get it to work along with the bigger script! Thank you!
 

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
17,252
Office Version
  1. 2013
Platform
  1. Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,567
Messages
5,596,908
Members
414,110
Latest member
docops

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
Top