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

Removing Filters and Unhiding Rows and Columns on Multiple Worksheets

Need to remove filters and display all rows and columns in all your worksheets? It is not easy to do manually, but with a ...

Discover More

Selecting a Table Row

If you need to select a single row in a table, Word provides several different ways that you can accomplish the task. ...

Discover More

Displaying the File Tab of the Ribbon by Default

When you first start Word, it displays the Home tab of the ribbon. If you want to display a different ribbon tab by ...

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

More ExcelTips (ribbon)

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

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

Floating Information in a Frozen Row

You can freeze information in rows or columns using one of the built-in features of Excel. As you move up or down in the ...

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 two more than 7?

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.