Renaming a lot of table arrays quickly.

snets123

New Member
Joined
Sep 10, 2021
Messages
8
Office Version
  1. 365
Platform
  1. Windows
Hi there,
I have a tricky situation. I have around 600 table arrays in a speadsheet that I must rename with specific GUIDS that I have. I know the technical way of going to Formulas-->Define Names-->Name Manager-->Selecting the table I want to rename and than entering the new name. Would anyone know of a way to do this that would help me from not having to do it manually? Some form of a vlookup..? Maybe a macro?
 
Yep, I took worksheetnames. But the method will be the same
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Yep, I took worksheetnames. But the method will be the same
So why would you give code that doesn't work for the OP? Method same but actual solution to question different, got it!
 
Last edited:
Upvote 0
Maybe because I misunderstood?
 
Upvote 0
Besides, since the OP has more than 600 ranges, you should use an array to generate your list.

VBA Code:
Sub jec()
   Dim ar()
   For Each sh In ThisWorkbook.Sheets
      For Each lo In sh.ListObjects
          ReDim Preserve ar(x)
          ar(x) = lo.Name
          x = x + 1
      Next
   Next
   With Sheets.Add
      .Name = "List"
      .Cells(1, 1).Resize(x) = Application.Transpose(ar)
   End With
End Sub
 
Upvote 0
OK, Had some more time to play, waiting for @snets123 to respond so I came up with the following code to gather the Table names from all of the worksheets, as well as the worksheet that the table is on, if that info would be desired. I also incorporated arrays, as suggested, to gather that information.

VBA Code:
Sub ListAllWorksheetsAndTableNames()                                        ' List all Worksheets/Table Names in the A/B columns of a new sheet
'
    Dim ListOfTableNamesSheetExists As Boolean
    Dim TableName                   As ListObject
    Dim RowCounter                  As Long
    Dim SheetCounter                As Long
    Dim TableCounter                As Long
    Dim ColumnA_ArrayList           As Object
    Dim ColumnB_ArrayList           As Object
    Dim ws                          As Worksheet
'
    Set ColumnA_ArrayList = CreateObject("System.Collections.ArrayList")    ' Set up ArrayList for Column A
    ColumnA_ArrayList.Add "Worksheet Name"                                  ' Add a Header to fill Item(0)
'
    Set ColumnB_ArrayList = CreateObject("System.Collections.ArrayList")    ' Set up ArrayList for Column B
    ColumnB_ArrayList.Add "Table Name"                                      ' Add a Header to fill Item(0)
'
    RowCounter = 0                                                          ' Initiate RowCounter
'
    For Each ws In Worksheets                                               ' Go through each worksheet in the worksheets object collection
        If ws.Name = "ListOfTableNames" Then ListOfTableNamesSheetExists = True ' If sheet name found then set flag to True
    Next
'
    If Not ListOfTableNamesSheetExists Then Sheets.Add.Name = "ListOfTableNames"    ' If aheet name not found then add it to the workbook
'
    For Each ws In Worksheets                                               ' Go through each worksheet in the worksheets object collection
        For Each TableName In ws.ListObjects                                '   Go through all table names located in the current worksheet
            RowCounter = RowCounter + 1                                     '       Increment RowCounter
'
            ColumnA_ArrayList.Add ws.Name                                   '       Save Worksheet name containing the Table to cell in column A
            ColumnB_ArrayList.Add TableName.Name                            '       Save Table name to cell in column B
        Next
    Next
'
'   Write results to columns A/B of Sheets("ListOfTableNames")
    Sheets("ListOfTableNames").Range("A1").Resize(ColumnA_ArrayList.Count, 1).Value = Application.Transpose(ColumnA_ArrayList.toArray)
    Sheets("ListOfTableNames").Range("B1").Resize(ColumnB_ArrayList.Count, 1).Value = Application.Transpose(ColumnB_ArrayList.toArray)
'
End Sub
 
Upvote 0
OK, Had some more time to play, waiting for @snets123 to respond so I came up with the following code to gather the Table names from all of the worksheets, as well as the worksheet that the table is on, if that info would be desired. I also incorporated arrays, as suggested, to gather that information.

VBA Code:
Sub ListAllWorksheetsAndTableNames()                                        ' List all Worksheets/Table Names in the A/B columns of a new sheet
'
    Dim ListOfTableNamesSheetExists As Boolean
    Dim TableName                   As ListObject
    Dim RowCounter                  As Long
    Dim SheetCounter                As Long
    Dim TableCounter                As Long
    Dim ColumnA_ArrayList           As Object
    Dim ColumnB_ArrayList           As Object
    Dim ws                          As Worksheet
'
    Set ColumnA_ArrayList = CreateObject("System.Collections.ArrayList")    ' Set up ArrayList for Column A
    ColumnA_ArrayList.Add "Worksheet Name"                                  ' Add a Header to fill Item(0)
'
    Set ColumnB_ArrayList = CreateObject("System.Collections.ArrayList")    ' Set up ArrayList for Column B
    ColumnB_ArrayList.Add "Table Name"                                      ' Add a Header to fill Item(0)
'
    RowCounter = 0                                                          ' Initiate RowCounter
'
    For Each ws In Worksheets                                               ' Go through each worksheet in the worksheets object collection
        If ws.Name = "ListOfTableNames" Then ListOfTableNamesSheetExists = True ' If sheet name found then set flag to True
    Next
'
    If Not ListOfTableNamesSheetExists Then Sheets.Add.Name = "ListOfTableNames"    ' If aheet name not found then add it to the workbook
'
    For Each ws In Worksheets                                               ' Go through each worksheet in the worksheets object collection
        For Each TableName In ws.ListObjects                                '   Go through all table names located in the current worksheet
            RowCounter = RowCounter + 1                                     '       Increment RowCounter
'
            ColumnA_ArrayList.Add ws.Name                                   '       Save Worksheet name containing the Table to cell in column A
            ColumnB_ArrayList.Add TableName.Name                            '       Save Table name to cell in column B
        Next
    Next
'
'   Write results to columns A/B of Sheets("ListOfTableNames")
    Sheets("ListOfTableNames").Range("A1").Resize(ColumnA_ArrayList.Count, 1).Value = Application.Transpose(ColumnA_ArrayList.toArray)
    Sheets("ListOfTableNames").Range("B1").Resize(ColumnB_ArrayList.Count, 1).Value = Application.Transpose(ColumnB_ArrayList.toArray)
'
End Sub
Thank you so much for this! Idid not have my access to my computer over the weekend but am back and very excited to see if I can get this working. I do have a table that contains all the automatically generated table tables in one column e.g. "Table56" and than a column beside that with all the required table names: e.g. "ObservationItems.167b187bf59d48899e90dfaf1b4b4656".
 
Upvote 0
I think all of us are in a different timezone to you, so we won't get to this tonight.
Can you just clarify what is the Table Name that has Old & New Table Name mapping.
Also we can work without it but the sheet name that the table is on, could be useful.

Ideally can you give us an XL2BB of the headings and first few rows of the Mapping Table.
If you can't do XL2BB at least a screenshot showing the Row & Column references and the Mapping table headings.

I tested your sample name and I am actually a bit surprised that it took a table name that was that long and had a full stop in the name but it did seem to work.
 
Upvote 0
I think all of us are in a different timezone to you, so we won't get to this tonight.
Can you just clarify what is the Table Name that has Old & New Table Name mapping.
Also we can work without it but the sheet name that the table is on, could be useful.

Ideally can you give us an XL2BB of the headings and first few rows of the Mapping Table.
If you can't do XL2BB at least a screenshot showing the Row & Column references and the Mapping table headings.

I tested your sample name and I am actually a bit surprised that it took a table name that was that long and had a full stop in the name but it did seem to work.
The current table name for the old/new names is called RenameOldNew and the tab name is just called Rename. Below I included a screen shot of the Rename tab with the RenameOldNew table in it. The ALLSCALES tab is the tab with all the other tables that are not renamed - they are all contained on one tab.
Screenshot 2021-09-13 095604.png
 
Upvote 0
Do we need to worry about the ALLSCALES tab or do we just run through RenameOldNew table and rename all the tables listed in there ?
 
Upvote 0
Do we need to worry about the ALLSCALES tab or do we just run through RenameOldNew table and rename all the tables listed in there ?
So all the tables that are currently named as "Table 26", "Table 27" etc. are all contained in the ALLSCALES tab and those were the ones I was looking to try to rename with those new names on the right side of the RenameOldNew table. Just trying to avoid having to manually rename each of the 600 tables in the ALLSCALES tab. If it makes it easier I can move the RenameOldNew into the ALLSCALES tab? Apologizes, I am very new to macros and trying to keep up!
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,539
Members
449,088
Latest member
RandomExceller01

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