For all named tables change name

darryl47nopra

New Member
Joined
Nov 26, 2024
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I have a lot of tables located in the same spreedsheet (placed on different columns different rows), all named table1, table2 etc.

My goal is change the name to their respective "header" located 1 row above and 3 columns to the rigth of each table.

So far I got something like this (but it is not working)

VBA Code:
Sub LoopThroughAllTablesWorksheet()


Dim ws As Worksheet
Dim tbl As ListObject

Set ws = ActiveSheet
For Each tbl In ws.ListObjects


    tbl.Names Names:=rngCell.Offset(-1, 2).Value
    

Next tbl

'End Sub
End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hello,
I think your code's structure is correct, however if you want to refer to the [-1,3] cell above the top left cell of the table, you should use
VBA Code:
tbl.Name = tbl.Range.Item(1).Offset(-1, 3).Value
In your code it is not known what "rngCell" is.
 
Upvote 0
Solution
Hello,
I think your code's structure is correct, however if you want to refer to the [-1,3] cell above the top left cell of the table, you should use
VBA Code:
tbl.Name = tbl.Range.Item(1).Offset(-1, 3).Value
In your code it is not known what "rngCell" is.
I really don't know how to the define the "rngCell" since it is different for each table, any suggestion?
 
Upvote 0
Did you try my proposition?

tbl.Range returns the range of the table, and tbl.Range.Item(1) the first cell in this range, ie. the top left one (as i wrote in my previous message).
 
Upvote 0
Did you try my proposition?

tbl.Range returns the range of the table, and tbl.Range.Item(1) the first cell in this range, ie. the top left one (as i wrote in my previous message).
Sorry I miss it at firts, but I've tried and It worked perfectly!!

Thank you so much!!
 
Upvote 0

Forum statistics

Threads
1,225,236
Messages
6,183,767
Members
453,188
Latest member
amenbakr

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