thedeadzeds
Active Member
- Joined
- Aug 16, 2011
- Messages
- 451
- Office Version
- 365
- Platform
- Windows
Hi All,
I've found the following code which works great. Is there a way to get this code to open all workbooks in a folder and run this for all worksheets called 'export' .
Thanks
I've found the following code which works great. Is there a way to get this code to open all workbooks in a folder and run this for all worksheets called 'export' .
Thanks
VBA Code:
Sub DeleteSelectedColumns()
Dim currentColumn As Integer
Dim columnHeading As String
For currentColumn = ActiveSheet.UsedRange.Columns.Count To 1 Step -1
columnHeading = ActiveSheet.UsedRange.Cells(1, currentColumn).Value
'Check whether to preserve the column
Select Case columnHeading
'Insert name of columns to preserve
Case "Date", "Name", "Amount Owing", "Balance"
'Do nothing
Case Else
'Delete the column
ActiveSheet.Columns(currentColumn).Delete
End Select
Next
End Sub