VBA macro to delete empty columns in excel

Excel VBA macro to delete empty columns. Just run this macro, enter number of columns you want to check and the macro checks (starting from first column) and deletes all empty columns within the selected number of columns.

In the macro, you can also find VBA syntax to delete empty row and to check whether a column is empty

VBA macro to delete empty columns

Sub deleteEmptyColumns()
Dim columnCount As Variant
columnCount = InputBox("Enter number of Columns that you want to check")
Range("A1").Select
Do
' syntax to check whether a Column is empty
If Application.CountA(ActiveCell.EntireColumn) = 0 Then
' syntax to delete a column
Selection.EntireColumn.Delete
Else
ActiveCell.Offset(0, 1).Select
End If
columnCount = columnCount - 1
Loop Until columnCount = 0
End Sub

 

About the Author

SRINI S

A passionate blogger. Love to share solutions and best practices on wordpress hosting, issues and fixes, excel VBA macros and other apps

Leave a Reply

Your email address will not be published.