parkerbelt
Active Member
- Joined
- May 23, 2014
- Messages
- 377
I have a program and I have some code that deletes columns from a table starting at week 2 and going to the right to the last column. I recorded the syntax from the Excel VBA recorder and it has quite a few lines. I want to condense it, so there aren't as many lines, as well as, make it more dynamic, because the number of columns will change in the future. Right now, starting at week 2 and going to the right, there are 18 columns, but in the future, there will be 50 or 52, etc...
Does anyone know how to make this code condensed and dynamic, so I can delete table columns?
Does anyone know how to make this code condensed and dynamic, so I can delete table columns?
Code:
Sheets("Test Stores - Chart Data").Select Range("Table1[[#Headers],[Week 2]]").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.ListObject.ListColumns(3).Delete
Selection.ListObject.ListColumns(3).Delete
Selection.ListObject.ListColumns(3).Delete
Selection.ListObject.ListColumns(3).Delete
Selection.ListObject.ListColumns(3).Delete
Selection.ListObject.ListColumns(3).Delete
Selection.ListObject.ListColumns(3).Delete
Selection.ListObject.ListColumns(3).Delete
Selection.ListObject.ListColumns(3).Delete
Selection.ListObject.ListColumns(3).Delete
Selection.ListObject.ListColumns(3).Delete
Selection.ListObject.ListColumns(3).Delete
Selection.ListObject.ListColumns(3).Delete
Selection.ListObject.ListColumns(3).Delete
Selection.ListObject.ListColumns(3).Delete
Selection.ListObject.ListColumns(3).Delete
Selection.ListObject.ListColumns(3).Delete
Selection.ListObject.ListColumns(3).Delete