Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. 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

by Allen Wyatt
(last updated November 15, 2014)

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.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (6149) applies to Microsoft Excel 2007, 2010, and 2013. 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

Renaming a Style

Styles are invaluable when it comes to applying consistent formatting in and across documents. If you need to rename a style ...

Discover More

Applying Styles

Styles are a powerful formatting tool for the text in your documents. Once you've created styles that describe how you want ...

Discover More

Using Microsoft Graph

Microsoft Graph is a simplistic graphic tool that you can use to quickly add graphs to your document. Here's how to start the ...

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)

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 to ...

Discover More

Spreading Out a Table

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 some ...

Discover More

Linked Combo Boxes

Want to add a great way to interact with your worksheet users? Try adding combo boxes that can modify the information shown ...

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}] 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 9 - 2?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


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.