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

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
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,214,650
Messages
6,120,736
Members
448,988
Latest member
BB_Unlv

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