I want to delete all columns in all worksheets of an Excel workbook except those named:
Date
Name
Amount Owing
Balance
The following code is working in the active worksheet:
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
How can I modify this code to apply on all worksheets?