Excel VBA How to detect if Object Table1 exists, and if yes, change its name to Table2?

Klash Ville

Board Regular
Joined
Sep 19, 2017
Messages
83
I have a couple issues that I will explain using the names Table1 and Table2 for easy understanding.

I want to check if object Table1 exists, and if it does, to change its name to Table2 and Select it as well.

How can I achieve this?
 

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)
You can try to reference the table with a variable and then after test to see if the variable was set or if it "Is Nothing" ... you use with On Error Resume Next, so it doesn't crash if the table does not exist. Just try to reference the sheet and from that then I think you try to reference the table as a ListObject using the table name. If setting a listobject or tableobject variable fails then it doesn't exist.

To reset error handling, after you use "On Error GoTo 0"
 
Upvote 0
You can try to reference the table with a variable and then after test to see if the variable was set or if it "Is Nothing" ... you use with On Error Resume Next, so it doesn't crash if the table does not exist. Just try to reference the sheet and from that then I think you try to reference the table as a ListObject using the table name. If setting a listobject or tableobject variable fails then it doesn't exist.

To reset error handling, after you use "On Error GoTo 0"

Could you provide me the line of code related to the ListObject.Table1 please

I'm a bit confused
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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