Test for table

Flyingmeatball

Board Regular
Joined
Aug 15, 2007
Messages
65
I'm being given a spreadsheet with thousands of rows of data and I need to run a VBA macro sorting, deleting, etc. The problem I'm having is sometimes I'm given the data in the form of a table, and sometmies not. If it is in the form of a table i need to unlist the table. To do that I'm using:

With sheets("sheet1").ListObjects("Table1")
Set rList = .Range
.Unlist
End With

the problem I'm having is devising a test to see if that table exists. There would only ever be one table. Can anyone think of a good boolean test that says something along the line of if sheets("sheet1").listobjects("table1").exists then unlist it?

Thanks!
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
A dirty solution would be this:
Code:
On Error Resume Next
With sheets("sheet1").ListObjects("Table1")
Set rList = .Range
.Unlist 
End With
On Error GoTo 0
When there is no ListObject called Table1, the code will silently fail and continue, if there is one, it will become unlisted...
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,524
Messages
6,179,304
Members
452,904
Latest member
CodeMasterX

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