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?
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Assuming your data on sheet "rename" is a real table:
Try this first on a copy of your workbook.

VBA Code:
Sub jec()
   ar = Sheets("Rename").ListObjects(1).DataBodyRange
   For i = 1 To UBound(ar)
      ThisWorkbook.Sheets("ALLSCALES").ListObjects(ar(i, 1)).Name = ar(i, 2)
   Next
End Sub
 
Upvote 0
The version I came up with:

VBA Code:
Sub RenameListOfTableNames()
'
    Dim LastRowOfTableNames     As Long
    Dim StartingRowOfNames      As Long
    Dim TableCounter            As Long
    Dim OldTableNamesArray()    As Variant
    Dim NewTableNamesArray()    As Variant
    Dim WS                      As Worksheet
'
    Set WS = Sheets("Rename")                                                                           ' <--- Change to sheet name desired
    StartingRowOfNames = 2                                                                              ' <--- Set this to the starting row of Table names
'
    LastRowOfTableNames = WS.Range("A" & Rows.Count).End(xlUp).Row                                      ' Find the row of the last Table Name

    OldTableNamesArray = Application.Transpose(WS.Range("A" & StartingRowOfNames & ":A" & LastRowOfTableNames)) ' Load current table names into array
    NewTableNamesArray = Application.Transpose(WS.Range("B" & StartingRowOfNames & ":B" & LastRowOfTableNames)) ' Load the new table names into array

    For TableCounter = 1 To UBound(OldTableNamesArray)                                                  ' Loop through Table Names to be renamed
        Sheets("ALLSCALES").ListObjects(OldTableNamesArray(TableCounter)).Name = NewTableNamesArray(TableCounter)   '   Rename each Table name
    Next
End Sub
 
Upvote 0
Solution
The version I came up with:

VBA Code:
Sub RenameListOfTableNames()
'
    Dim LastRowOfTableNames     As Long
    Dim StartingRowOfNames      As Long
    Dim TableCounter            As Long
    Dim OldTableNamesArray()    As Variant
    Dim NewTableNamesArray()    As Variant
    Dim WS                      As Worksheet
'
    Set WS = Sheets("Rename")                                                                           ' <--- Change to sheet name desired
    StartingRowOfNames = 2                                                                              ' <--- Set this to the starting row of Table names
'
    LastRowOfTableNames = WS.Range("A" & Rows.Count).End(xlUp).Row                                      ' Find the row of the last Table Name

    OldTableNamesArray = Application.Transpose(WS.Range("A" & StartingRowOfNames & ":A" & LastRowOfTableNames)) ' Load current table names into array
    NewTableNamesArray = Application.Transpose(WS.Range("B" & StartingRowOfNames & ":B" & LastRowOfTableNames)) ' Load the new table names into array

    For TableCounter = 1 To UBound(OldTableNamesArray)                                                  ' Loop through Table Names to be renamed
        Sheets("ALLSCALES").ListObjects(OldTableNamesArray(TableCounter)).Name = NewTableNamesArray(TableCounter)   '   Rename each Table name
    Next
End Sub
It was a success!
Thanks for all your help @johnnyL, @*JEC , @Alex Blakenburg
 
Upvote 0

Forum statistics

Threads
1,215,446
Messages
6,124,896
Members
449,194
Latest member
JayEggleton

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