Excel VBA renames table

simmerer

New Member
Joined
Sep 6, 2017
Messages
33
Hi,
I have a macro that changes a range into a table. This workbook does not have any tables to begin with. I am creating new functions in the workbook, so I am adding some new sheets created in another workbook, which have tables 2,3, and 4 (Table2, Table3, Table4). When the macro is run I expect it to name the new table as Table1. I have code that runs after, which refers to "Table1" when it creates a formula in a cell.

Alas, excel creates the table, and names it "Table1_1". Rats!

I expect that somewhere in memory, Table1 has some reference that excel sees, so offers up the rename.

I have run this code in test multiple times, closing the workbook without saving. The rename continues to create Table1_1.

Here is the question - Can I count on Table1_1, or will that also become an unseen object reference causing me to have the same issue later with excel using Table1_2 or something else?

I am considering having the code rename the table first, if possible, then continuing. I just am not sure what excel will do with that.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
I believe there's a way to see what tables are open in the workbook. If someone doesn't answer in time I'd recommend Googling how to open existing workbook, getting the active sheet, and finding tables that are active on sheet.
 
Upvote 0
Why not just change the macro that creates the table, to name the table what you want it to be.

Code:
Sheet1.ListObjects.Add(xlSrcRange, Range("A1:C30"), , xlYes).Name = "Table1"
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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