AOB
Well-known Member
- Joined
- Dec 15, 2010
- Messages
- 667
- Office Version
- 365
- 2016
- 2013
- Platform
- Windows
Hi everybody,
I need some code to convert all tables in a workbook to "flat" ranges (that is, retain the data, just get rid of the table structure around it)
I thought this would be fairly straightforward :
But for some reason it throws a run-time error (1004) every time it tries to unlist the object?
My first instinct was that I couldn't unlist a listobject while it is held as a ListObject variable (i.e. by doing so, it is no longer a ListObject variable, thus conflict)
So then I tried just compiling a list of table names and then unlisting them individually outside the object scope like so :
But I just get the same error?
Any suggestions?
I need some code to convert all tables in a workbook to "flat" ranges (that is, retain the data, just get rid of the table structure around it)
I thought this would be fairly straightforward :
Code:
Public Sub FlattenTables()
Dim sht As Worksheet
Dim lso As ListObject
For Each sht In ThisWorkbook.Sheets
For Each lso In sht.ListObjects
lso.Unlist
Next lso
Next sht
End Sub
But for some reason it throws a run-time error (1004) every time it tries to unlist the object?
Application-defined or object-defined error
My first instinct was that I couldn't unlist a listobject while it is held as a ListObject variable (i.e. by doing so, it is no longer a ListObject variable, thus conflict)
So then I tried just compiling a list of table names and then unlisting them individually outside the object scope like so :
Code:
ThisWorkbook.Sheets("SheetName").ListObjects("TableName").Unlist
But I just get the same error?
Any suggestions?
Last edited: