willow1985
Well-known Member
- Joined
- Jul 24, 2019
- Messages
- 888
- Office Version
- 365
- Platform
- Windows
I have tried a few codes online but I cannot find one that does what I am looking for.
I have a table called "PDF" on Sheet "PDF".
What I would like is a code that deletes every column in this table minus the first one so the table still exists and is ready to accept new data (therefor expanding accordingly)
The table starts on cell A36. I already have a code that clears all of the rows below A37 but it is the columns that are the problem as I need to keep the sheet columns as there is data above the table and the headers of the table can vary. It would be better if there was a way to use relative references and delete columns 2-12 for example but without deleting the table.
The below code unfortunately seems to delete the table
Any help with this code would be greatly appreciated!!
ALSO if there was any way to delete any column that contains the word "Column" ?? Basically if the column has no data I would like it deleted from the Table.
Thank you
I have a table called "PDF" on Sheet "PDF".
What I would like is a code that deletes every column in this table minus the first one so the table still exists and is ready to accept new data (therefor expanding accordingly)
The table starts on cell A36. I already have a code that clears all of the rows below A37 but it is the columns that are the problem as I need to keep the sheet columns as there is data above the table and the headers of the table can vary. It would be better if there was a way to use relative references and delete columns 2-12 for example but without deleting the table.
The below code unfortunately seems to delete the table
VBA Code:
'Declare Variables
Dim oSheetName As Worksheet
Dim sTableName As String
Dim loTable As ListObject
'Define Variable
sTableName = "PDF"
'Define WorkSheet object
Set oSheetName = Sheets("PDF")
'Define Table Object
Set loTable = oSheetName.ListObjects(sTableName)
'Loop through to delete
For iCnt = 2 To 12
'Delete multiple columns from the table
loTable.ListColumns(1).Delete
Next
Any help with this code would be greatly appreciated!!
ALSO if there was any way to delete any column that contains the word "Column" ?? Basically if the column has no data I would like it deleted from the Table.
Thank you
Last edited: