Note: The other languages of the website are Google-translated. Back to English
English English

How to delete empty columns with header in Excel?

If you have a large worksheet which contains multiple columns, but some of the columns only contain a header, and now, you want to delete theses empty columns which with only a header to get the following screenshot shown. Is this can be solved in Excel quickly and easily?

doc delete blank columns with header 1

Delete empty columns with a header by using VBA code

Delete multiple empty columns in a range / worksheet / workbook with Kutools for Excel


arrow blue right bubble Delete empty columns with a header by using VBA code

In Excel, there is no direct method to deal with this job excepting delete them one by one manually, but, here, I can introduce a code for you, please do as follows:

1. Hold down the ALT + F11 keys, then it opens the Microsoft Visual Basic for Applications window.

2. Click Insert > Module, and paste the following code in the Module Window.

VBA code: Delete empty columns with a header:

Sub Macro1()
'updateby Extendoffice
    Dim xEndCol As Long
    Dim I As Long
    Dim xDel As Boolean
    On Error Resume Next
    xEndCol = Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
    If xEndCol = 0 Then
        MsgBox "There is no data on """ & ActiveSheet.Name & """ .", vbExclamation, "Kutools for Excel"
        Exit Sub
    End If
    Application.ScreenUpdating = False
    For I = xEndCol To 1 Step -1
        If Application.WorksheetFunction.CountA(Columns(I)) <= 1 Then
            Columns(I).Delete
            xDel = True
        End If
    Next
    If xDel Then
        MsgBox "All blank and column(s) with only a header row have now been deleted.", vbInformation, "Kutools for Excel"
    Else
        MsgBox "There are no Columns to delete as each one has more data (rows) than just a header.", vbExclamation, "Kutools for Excel"
    End If
    Application.ScreenUpdating = True
End Sub

3. Then press F5 key to run this code, and a prompt box will pop out to remind you the blank columns with header will be deleted, see screenshot:

doc delete blank columns with header 2

4. And then click OK button, all the blank columns with only header in current worksheet are deleted at once.

Note: If there are blank columns, they will be deleted as well.


arrow blue right bubble Delete multiple empty columns in a range / worksheet / workbook with Kutools for Excel

Sometimes, you just only need to delete the blank columns, the Kutools for Excel’s Delete Hidden (Visible) Rows & Columns utility can help you to finish this task with ease.

Kutools for Excel : with more than 300 handy Excel add-ins, free to try with no limitation in 30 days. 

After installing Kutools for Excel, please do as follows:

1. Select the columns range which include the blank columns need to be deleted.

2. Then click Kutools > Delete > Delete Hidden (Visible) Rows & Columns, see screenshot:

3. In the Delete Hidden (Visible) Rows & Columns dialog box, you can select the delete scope from the Look in drop down as you need, select Columns from the Delete type section, and then choose Blank columns from the Detailed type section, see screenshot:

doc delete blank columns with header 4

4. Then click Ok button, and only the empty columns are deleted at once. See screenshot:

doc delete blank columns with header 5

Tips: With this powerful feature, you can also delete blank rows, visible columns or row, hidden columns or rows as you need.

Click Free Download Kutools for Excel Now!


The Best Office Productivity Tools

Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.
kte tab 201905

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
officetab bottom
Comments (10)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
Hi, Thanks for the nice code above. Is it free to use?
This comment was minimized by the moderator on the site
OMG, this is genius!!! thank you
This comment was minimized by the moderator on the site
Works perfectly. Greatly appreciated
This comment was minimized by the moderator on the site
Can this be saved in one spreadsheet and run on other files?
This comment was minimized by the moderator on the site
All I keep getting is "There are no Columns to delete as each one has more data (rows) than just a header." Yet I know for a fact I have about 700 columns with a header and no data. I have a spreadsheet with over 900 columns and only 200ish have data below the header. Another macro worked but I had to delete the header row. So I know this macro is not working correctly. What's up?
This comment was minimized by the moderator on the site
Hello, Paul
The VBA code works well if there is only one header row in the worksheet, if there are two or more header rows, it will pop out the prompt message you said.
So you need to check out if there are hidden heading rows in your data.
Thank you!
This comment was minimized by the moderator on the site
Amazing! You are correct. There must have been something hidden. Everything is working great now. Thank you so much for the quick reply.
This comment was minimized by the moderator on the site
Hello, I have the same issue, I know by fact that I have a lot of columns that have only headers but the same Error "There are no Columns to delete as each one has more data (rows) than just a header." and I have checked there are no hidden rows in the data.
Can anyone help me ?
This comment was minimized by the moderator on the site
Hi, Simoch
In this case, you can upload your Excel file attachment here, so that we can help to check the problem if you don't mind.
Thank you!
This comment was minimized by the moderator on the site
Dear skyyang no need, It worked perfecty now !! thank you so much for that VBA code !
Rated 5 out of 5
There are no comments posted here yet
Leave your comments
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations