This macro will delete columns which are completely empty. This means that if there is no data within the entire column it will be removed. This macro works on a selection of cells within the excel spreadsheet. That means that you must select cells and then run the macro for it to do anything.
Note: The first macro will work for Excel 2007 whereas the second macro will work for Previous Excel Versions. This is due to the change in the number of rows from previous excel versions to Excel 2007.
Sub Delete_Empty_Columns()
first = Selection.Column
last = Selection.Columns(Selection.Columns.Count).Column
For i = last To first Step -1
If WorksheetFunction.CountBlank(ActiveSheet.Columns(i)) = 1048576 Then
Columns(i).Delete
End If
Next i
End Sub
Sub Delete_Empty_Columns()
first = Selection.Column
last = Selection.Columns(Selection.Columns.Count).Column
For i = last To first Step -1
If WorksheetFunction.CountBlank(ActiveSheet.Columns(i)) = 65536 Then
Columns(i).Delete
End If
Next i
End Sub