Under your data, enter =COUNTA(A1:A4) and copy it across. Columns showing 0 are completely empty: Ctrl-click their letters, then Home › Delete › Delete Sheet Columns. Columns with only a few blanks are kept.
=COUNTA(A1:A4)
You pasted a report or exported a file and now there are empty columns between your data. They push useful columns off screen and break sorting and formulas.
The safe way removes only columns that are empty in every cell. Go To Special › Blanks followed by deleting columns also removes any column that has a single gap, such as a customer name that's missing on one row.
Step by step
- In the first empty row below your data (here row 6), enter =COUNTA(A1:A4) in column A. Make the range cover every row of your data, including the header.
- Copy it across under every column: select A6 to the last column (here E6) and press Ctrl + R.
- Columns showing 0 are completely empty. Click the first such column letter, then Ctrl-click the others.
- Right-click one of the selected letters and choose Delete (or press Ctrl + -). The columns to the right move left.
- Delete the helper row, then check your data. Press Ctrl + Z straight away if something looks wrong.
On a Mac: The steps are the same. To pick several columns, Cmd-click their letters, then Control-click one and choose Delete.
Before and after
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Order | Customer | Amount | ||
| 2 | 1001 | Ana | 250 | ||
| 3 | 1002 | 180 | |||
| 4 | 1003 | Ben | 320 | ||
| 5 | |||||
| 6 | 4 | 0 | 3 | 0 | 4 |
| A | B | C | |
|---|---|---|---|
| 1 | Order | Customer | Amount |
| 2 | 1001 | Ana | 250 |
| 3 | 1002 | 180 | |
| 4 | 1003 | Ben | 320 |
The macro
Press Alt+F11, choose Insert › Module, paste the code, then press F5 to run it. Save the file as .xlsm to keep the macro.
Delete columns that are completely empty on the active sheet
Sub DeleteEmptyColumns()
' Deletes only columns with nothing in any cell
Dim ws As Worksheet, last As Range, c As Long
Set ws = ActiveSheet
Set last = ws.Cells.Find(What:="*", LookIn:=xlFormulas, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious)
If last Is Nothing Then Exit Sub ' the sheet is empty
For c = last.Column To 1 Step -1
If Application.WorksheetFunction.CountA(ws.Columns(c)) = 0 Then ws.Columns(c).Delete
Next c
End SubWith a formula instead
| Formula | Use it when |
|---|---|
=FILTER(A1:E4,BYCOL(A1:E4,LAMBDA(c,COUNTA(c)>0))) | You want a clean copy without the empty columns, leaving the original untouched (Microsoft 365). |
Practise it
Free exercises with instant feedback. No sign-up needed.
Common mistakes
- Go To Special › Blanks, then deleting entire columns, removes every column with any empty cell, including one with a single missing value. Count each column's filled cells with =COUNTA(A1:A4) and delete only the columns where it is 0.
- Deleting cells instead of whole columns shifts data up and misaligns rows. Select the column letters and choose Delete, so whole columns are removed.
- Cells that look empty contain spaces or formulas returning "", so COUNTA counts them. Use =SUMPRODUCT(--(LEN(TRIM(A1:A4))>0)) instead: it counts only cells with visible text or numbers.
Questions people also ask
Why not use Go To Special › Blanks?
It selects every empty cell, so deleting entire columns also deletes columns that have just one missing value. It's fine for selecting or filling empty cells, not for deleting whole columns.
Can I remove empty columns without deleting anything?
Yes. Use =FILTER(A1:E4,BYCOL(A1:E4,LAMBDA(c,COUNTA(c)>0))) on another sheet for a clean copy (Microsoft 365), or hide the empty columns instead.
What about a column that only has a header?
The helper counts the header, so a header-only column shows 1 and is kept. Start the range at row 2 (=COUNTA(A2:A4)) if you want those removed too.
Functions used
Steps written for Excel for Microsoft 365 on Windows. All how-to guides