Features of !SEMTools
↑ Navigate Excel tasks and !SEMTools add-in features ↑

How to delete empty columns in Excel

, creator of !SEMToolsUpdated 4 min readTopics: Excel basics

Need to delete empty columns in Excel on one sheet or on several? Unlike rows, Excel has no filter for columns, so the usual tricks don’t work. Here are a few simple ways to get rid of them.

Find empty columns with a formula

In a free row above or below the table, put this formula under the first column and fill it to the right. It returns TRUE for columns that are completely empty within the data range:

=COUNTA(A2:A1000)=0
Mark empty columns
B5=COUNTA(B2:B4)=0
ABCDE
1NameCitySales
2AnnaNY120
3Bob80
4CleoLA95
5FALSE=COUNTA(A2:A4)=0TRUE=COUNTA(B2:B4)=0FALSE=COUNTA(C2:C4)=0TRUE=COUNTA(D2:D4)=0FALSE=COUNTA(E2:E4)=0

The check counts filled cells below the header. Columns B and D are TRUE — empty. In C, Bob’s blank doesn’t matter: the column has data. If empty columns have headers, start the range below the header row, as here.

Then select the columns marked TRUE (hold Ctrl and click their letters), right-click and choose Delete. Fine for a dozen columns, tedious for a hundred.

In Excel 365, a copy of the table without empty columns is one formula:

=FILTER(A1:Z1000,BYCOL(A1:Z1000,LAMBDA(c,COUNTA(c)>0)))
A copy without empty columns (Excel 365)
G2=FILTER(A2:E4,BYCOL(A2:E4,LAMBDA(c,COUNTA(c)>0)))
ABCDEFGHI
1NameCitySalesNameCitySales
2AnnaNY120Anna=FILTER(A2:E4,BYCOL(A2:E4,LAMBDA(c,COUNTA(c)>0)))NY120
3Bob80Bob80
4CleoLA95CleoLA95

BYCOL applies COUNTA to each column, and FILTER keeps the columns with at least one value. Include the header row in the range if the empty columns have no header.

VBA code to delete empty columns

You can delete empty columns with simple VBA code. The first procedure removes empty columns from a given sheet, the second runs it on the active sheet, and the third on all sheets of the workbook. It goes from right to left, so that deleting a column doesn’t shift the ones still to be checked:

Sub DeleteEmptyColumnsOnSheet(ws As Worksheet)
    Dim i As Long, lastCol As Long
    lastCol = ws.UsedRange.Column + ws.UsedRange.Columns.Count - 1
    For i = lastCol To 1 Step -1
        If Application.WorksheetFunction.CountA(ws.Columns(i)) = 0 Then ws.Columns(i).Delete
    Next i
End Sub

Sub DeleteEmptyColumnsActiveSheet()
    DeleteEmptyColumnsOnSheet ActiveSheet
End Sub

Sub DeleteEmptyColumnsInWorkbook()
    Dim ws As Worksheet
    For Each ws In ActiveWorkbook.Worksheets
        DeleteEmptyColumnsOnSheet ws
    Next ws
End Sub

How to use the code

  • Press Alt+F11 to open the VBA editor.
  • Right-click your workbook in the project tree and choose Insert → Module.
  • Paste the code into the empty module window.
  • Run DeleteEmptyColumnsActiveSheet or DeleteEmptyColumnsInWorkbook with Alt+F8.

There are a couple of catches:

  • the code can run only while the workbook where it’s saved is open, which is very inconvenient;
  • regular .xlsx files can’t store code, so you have to save the workbook as .xlsm or .xlsb;
  • a macro can’t be undone with Ctrl+Z, so save a copy first.

Storing the code in the Personal Macro Workbook (PERSONAL.XLSB) is a bit more convenient: then it’s available in every workbook.

Delete empty columns in 2 clicks with !SEMTools

The solutions above work, but once you get into automation, the number of formulas and macros grows fast, and so does the time spent looking for the right one. My add-in solves this: hundreds of small solutions are arranged as intuitively as possible.

Delete empty columns on a sheet

With !SEMTools, deleting the empty columns from the active sheet is very simple: choose DELETE → Ranges → Empty columns → On active sheet, and all empty columns are deleted instantly.

Delete empty columns in a workbook

If there are empty columns on several sheets, Empty columns → On all sheets in active workbook deletes them from every sheet at once.

The procedure is available in the free version of !SEMTools. Install it and use it.

See also:

Delete empty columns on a sheet or in the whole workbook in 2 clicks, without VBA or helper rows.
!SEMTools solves this and 500+ other tasks in Excel, and this procedure is free!

Summary: how to remove blank columns

I hope you found what you were looking for on this page and were able to delete the empty columns. A COUNTA check row works for small tables, FILTER with BYCOL in Excel 365 gives a clean copy, VBA handles whole workbooks, and the free !SEMTools procedure does the same in 2 clicks without any code.

You may also be interested in how to delete empty rows in Excel.