Skip to main content

How to delete multiple empty columns quickly in Excel?

Sometimes when you import data to Microsoft Excel from some source, such as web page, CSV, text, etc., there may be many empty columns with it. It must be time-consuming to delete each empty column one by one. Therefore, some of us search for easy ways to solve this problem. This article collects some tricky tips to help you delete multiple empty columns quickly.

Delete multiple empty columns in worksheet with formula

Delete multiple empty columns in worksheet with VBA code

Delete multiple empty columns in selection / active sheet / whole workbook with a useful feature

Delete multiple empty columns with a header by using VBA code


Delete multiple empty columns in worksheet with formula

In Excel, you can apply a formula to indentify if the columns are blank or not, and then use the Sort feature to sort all blank columns together, and then delete them at once. Please do as this:

1. Add a new row at the top of your data range, see screenshot:

2. Then enter the below formula into cell A1, and then drag the fill handle to right side to apply this formula to other cells, a TRUE will be displayed if the column is blank, otherwise, a FALSE is displayed, see screenshot:

=COUNTA(A2:A1048576)=0

3. Then select the data range including the helper row, and then click Data > Sort, see screenshot:

4. In the popped out Sort dialog box, click Options button, in the following Sort Options dialog, select Sort left to right option, see screenshots:

5. Click OK button to return the Sort dialog, then select Row 1 from the Sort by drop down, and select Cell Values from Sort On section, choose Largest to Smallest from the Order section, see screenshot:

6. Then, all empty columns have been sorted at the left of your data, and now, you just need to select all columns and then right click, choose Delete to delete these blank columns at once, see screenshot:


Delete multiple empty columns in worksheet with VBA code

If you'd like to use VBA macro, things goes much easier. The following VBA code may help you, please do as this:

1. Hold down the Alt + F11 keys in Excel, and it opens the Microsoft Visual Basic for Applications window.

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

VBA code: Delete multiple blank columns in selection:

Sub DeleteEmptyColumns()
'Updateby Extendoffice
Dim rng As Range
Dim InputRng As Range
xTitleId = "KutoolsforExcel"
Set InputRng = Application.Selection
Set InputRng = Application.InputBox("Range :", xTitleId, InputRng.Address, Type:=8)
Application.ScreenUpdating = False
For i = InputRng.Columns.Count To 1 Step -1
    Set rng = InputRng.Cells(1, i).EntireColumn
    If Application.WorksheetFunction.CountA(rng) = 0 Then
        rng.Delete
    End If
Next
Application.ScreenUpdating = True
End Sub

3. Press the F5 key to run this macro, select the work range you need in the pop out dialog. See screenshot:

4. Click OK, then all empty columns in the selection are removed. See screenshot:


Delete multiple empty columns in selection / active sheet / whole workbook with a useful feature

The Delete Hidden (Visible) Rows & Columns utility of Kutools for Excel can help you quickly remove multiple empty rows or columns at once.

Tips:To apply this Delete Hidden (Visible) Rows & Columns feature, firstly, you should download the Kutools for Excel, and then apply the feature quickly and easily.

After installing Kutools for Excel, please do as this:

1. Click Kutools > Delete > Delete Hidden (Visible) Rows & Columns, see screenshot:

2. In the Delete Hidden (Visible) Rows & Columns dialog box, specify the scope that you want to apply the operation from Look in drop down list. (If you choose In Selected Range, you must select a range that you want to use first.) And then check Columns under Delete type. And select Blank columns from Detailed type. See screenshot:

3. Then click OK. And the blank columns have been deleted from the selected range. See screenshot:


Delete multiple empty columns with a header by using VBA code

Sometimes, you may want to delete all the empty columns which contain only a header in the worksheet, the following VBA code can do you a favor, please do with the following steps:

1. Hold down the Alt + F11 keys in Excel, and it opens the Microsoft Visual Basic for Applications window.

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

VBA code: Delete all empty columns with a header

Sub deleteblankcolwithheader()
'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 column(s) with only a header row have 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:

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


More relative articles:

  • Delete All Hidden Rows Or Columns In Excel
  • If you have a large workbook with a lot of hidden rows and columns, and now the hidden data are unavailable, you would like to delete all of them. How could you quickly delete them?
  • Delete All Pictures Or Other Objects In Excel
  • If you want to delete all pictures from Microsoft Excel, it may be time-consuming to select each picture and delete them one by one. The following tricks may ease your work to delete all pictures.
  • Delete Rows Based On Background Color In Excel
  • How could you delete entire rows based on background color? In this example, I need to delete all rows which cells filled with blue background color as following screenshot shown. With this article, you will get some codes to achieve this task in Excel.

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...

Description


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!

Comments (8)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
It deleted all my names in my first name column! Auuggh!
This comment was minimized by the moderator on the site
Thanks its very helpful page with basic excel option :)
This comment was minimized by the moderator on the site
Hi, can anyone guide how i can delete blank cells in a row or column...note whole blank column or rows... only blank cell i need to delete in a column
This comment was minimized by the moderator on the site
Hello,


try to implement below code
This comment was minimized by the moderator on the site
Hi, the thing which you are mentioned is so helpfull. I want a small help from your side. Daily am download the some files and using pivot prepared the reports. It is daily task for me and routine process. How can i do it with out using pivot. Ex: If i prepared the reports on yesterday in "A" Excel file. Next day in "A" Excel file just i replace the new "B" Excel file data. By this automatically report would be create? Is it possible?
This comment was minimized by the moderator on the site
Very helpful page. Thank you. :-) My challenge is that I have columns with headers, but no data in that column. Only the header is present. How would one go about deleting columns where there is no data, but the header is there? :o
This comment was minimized by the moderator on the site
the above details are very helpful for my personal use. Thanks for your guidance. M.KARTHIKEYAN :-)
This comment was minimized by the moderator on the site
I found it much simpler to go to the line after my last line of data, enter "Shift-Ctrl-End" to highlight all blank lines that followed(much faster), right click and enter "delete all rows/columns". The system didn't waste so much time searching this way and so it was clean in the blink of an eye and files that were 20 MB were dropped to a size of 20 kb.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations