Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

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 20160616
    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 60 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:

doc delete blank columns with header 3

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!


Recommended Productivity Tools

Ribbon of Excel (with Kutools for Excel installed)

300+ Advanced Features Increase Your Productivity by 71%, and Help You To Stand Out From Crowd!

Would you like to complete your daily work quickly and perfectly? Kutools For Excel brings 300+ cool and powerful advanced features (Combine workbooks, sum by color, split cell contents, convert date, and so on...) for 1500+ work scenarios, helps you solve 82% Excel problems.

  •  Deal with all complicated tasks in seconds, help to enhance your work ability, get success from the fierce competition, and never worry about being fired.
  •  Save a lot of work time, leave much time for you to love and care the family and enjoy a comfortable life now.
  •  Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands, and give you a healthy body.
  •  Become an Excel expert in 3 minutes, and get admiring glance from your colleagues or friends.
  •  No longer need to remember any painful formulas and VBA codes, have a relaxing and pleasant mind, give you a thrill you've never had before.
  •  Spend only $39, but worth than $4000 training of others. Being used by 110,000 elites and 300+ well-known companies.
  •  60-day unlimited free trial. 60-day money back guarantee. Free upgrade and support for 2 years. Buy once, use forever.
  •  Change the way you work now, and give you a better life immediately!

Office Tab Brings Efficient And Handy Tabs to Office (include Excel), Just Like Chrome, Firefox, And New IE

  • Increases your productivity by 50% when viewing and editing multiple documents.
  • Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
  • Open and create documents in new tabs of same window, rather than in new windows.
  • Help you work faster and easily stand out from the crowd! One second to switch between dozens of open documents!
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Kim · 1 years ago
    OMG, this is genius!!! thank you
  • To post as a guest, your comment is unpublished.
    Roger · 2 years ago
    Hi,

    Thanks for the nice code above.
    Is it free to use?