Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Deleting Blank Columns.

Deleting Blank Columns

Written by Allen Wyatt (last updated April 10, 2021)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


2

When importing information from an external source, it is possible that the data will contain blank columns—columns with nothing in them. If you import a lot of data, then deleting these columns can be a bother. There are a couple of ways you can approach how to delete these columns.

The first approach works very well if your data is sorted by column. In other words, the data that you import is in ascending order, or you want it in sorted order. In this case, follow these steps:

  1. Select the columns that represent your data. Make sure you select, as part of the range, all the blank columns as well.
  2. Display the Data tab of the ribbon.
  3. Click the Sort tool. Excel displays the Sort dialog box.
  4. Click the Options button. Excel displays the Sort Options dialog box. (See Figure 1.)
  5. Figure 1. The Sort Options dialog box.

  6. Choose the Sort Left to Right radio button.
  7. Click on OK to dismiss the Sort Options dialog box.
  8. Using the first Sort By drop-down list, specify the row by which you want to sort.
  9. Click on OK.

When sorting in this manner, all the empty columns end up "pushed" to the right, and your data is in a sorted order.

If you don't want your data sorted, then you can use a nifty macro that will check for blank columns in a selected range and then delete those columns. The following macro will do the trick:

Sub DeleteEmptyColumns()
    first = Selection.Column
    last = Selection.Columns(Selection.Columns.Count).Column
    For i = last To first Step -1
        If WorksheetFunction.CountBlank(ActiveSheet.Columns(i)) _
          = ActiveSheet.Rows.Count Then
            Columns(i).Delete
        End If
    Next i
End Sub

To use the macro, select the range of columns in which you want blank columns deleted. The macro steps through the columns and if the column is truly blank, it is deleted. You should note that this macro will delete only columns that are truly empty. If cells within a column include a formula that returns a zero value (and you have the display of zeros values turned off) or that returns an empty string, then the column isn't empty—it contains formulas. In this case, the column won't be deleted.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (6149) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Deleting Blank Columns.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Adding Comments to Your Document

If you would like to add non-printing notes to your document, the Comments feature is one way of doing that. Here's how ...

Discover More

Using the Object Browser

Efficiently navigating through a document, particularly as it gets longer, can be a perpetual challenge. One tool you can ...

Discover More

Replacing a Colon in a Sequence

Sometimes you'll run across the need to replace a very specific sequence of characters in your document. It is for these ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (ribbon)

Inserting and Copying Rows

Want an easy way to insert a new row in a worksheet and copy everything from the row above? (You end up with two ...

Discover More

Making a Named Range Non-Scrollable

Excel provides a few ways that you can freeze or split what you see in your worksheet. The appropriateness of these tools ...

Discover More

Spreading Out Worksheet Rows

If someone sends you a worksheet that has lots of data in it, you might want to "spread out" the data so you can have ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is three minus 2?

2021-04-11 04:35:45

JohnT

I often do this, import text into Excel and then want to clean it up by deleting unwanted rows (or columns) .Often the unwanted ones have something specific to identify them (a value in a given cell) or it could the that the wanted ones have that marker.
So to delete unwanted rows, I add a column usually to the left. Sequence the cells (1 in A1, =A1+1 in A2 and copy it all the way down. Make it fixed (Ctl-A to select all, Ctl-C to copy all, then paste special values.
Now we're set up.
Sort the spread sheet by the column with the markers and quickly delete unwanted rows..
Finally resort by column 1 (with the sequences) and then delete column 1

It's actually a lot easier than it sounds.


2021-04-10 08:17:18

Mark

If you do this import often I'd suggest using Power Query (PQ). Not only can you very easily discard the empty columns you can also perform any other data preparation functions you might need.
I'll admit that as of now it's not trivial to set-up PQ for variable file names but there are some good tips in other web-sites on how to make it more flexible.

One such source is: https://www.excelguru.ca/blog/2014/11/26/building-a-parameter-table-for-power-query/

Thanks


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.