rename A LOT of tables on several worksheets

dsause

New Member
Joined
Jun 18, 2021
Messages
1
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I have several worksheets with dozens (...even hundreds) of tables and none of them were named, so i have a bunch of tables with names like "Table4858333454" .
I need no rename them all based on the worksheet they are in, and the name in the A1 (top left header) section of the table. AND some tables have more than one word, "Something Healthcare Partner" .. so there's spaces too

There is also two tables (side-by-side) for each 'Something Healthcare Partners'... So i have two tables that need distinction
[image bellow]


Worksheet name: 'West Coast Analytics'
Table top left header: 'Something Healthcare Partners'

What I'd like the rename each table to: "West_Coast_a1_Something_Healthcare_Partners"
(and for the one next to it "West_Coast_a2_Something_Healthcare_Partners")

I am pretty new to VBA and know I will have to use it for this

Can I get help as to where to start or what the solution may look like?

Thanks
 

Attachments

  • Screenshot (2).png
    Screenshot (2).png
    18 KB · Views: 9

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Try this code:

Dim i, N As Integer
N = 9999 'N being the number of tables
For i = 1 To N 'loop through worksheets
Sheets(i).Select
Tname = ActiveCell.ListObject.Name 'Assign current table name to a variable
Qname = ActiveSheet.Name 'Assign current worksheet name to a variable
Sname = ActiveSheet.Range("A1") 'Assign the info in cell A1 to a variable
ActiveSheet.ListObjects(ans).Name = Qname & "_" & Sname 'Rename the table
Next i

Let me know if this helps you
 
Upvote 0
sorry....small typo in the above code:

Dim i, N As Integer
N = 9999 'N being the number of tables
For i = 1 To N 'loop through worksheets
Sheets(i).Select
Tname = ActiveCell.ListObject.Name 'Assign current table name to a variable
Qname = ActiveSheet.Name 'Assign current worksheet name to a variable
Sname = ActiveSheet.Range("A1") 'Assign the info in cell A1 to a variable
ActiveSheet.ListObjects(Tname).Name = Qname & "_" & Sname 'Rename the table
Next i
 
Upvote 0

Forum statistics

Threads
1,215,386
Messages
6,124,628
Members
449,176
Latest member
Dazjlbb

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