
You should note that this macro will delete only columns that are truly empty. The macro steps through the columns and if the column is truly blank, it is deleted. To use the macro, select the range of columns in which you want blank columns deleted. If WorksheetFunction.CountBlank(ActiveSheet.Columns(i)) = 65536 Then
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. When sorting in this manner, all the empty columns end up "pushed" to the right, and your data is in a sorted order.
Using the first Sort By drop-down list, specify the row by which you want to sort. Click on OK to dismiss the Sort Options dialog box. Choose the Sort Left to Right radio button. Excel displays the Sort Options dialog box. Choose the Sort option from the Data menu. Make sure you select, as part of the range, all the blank columns as well.
Select the columns that represent your data. In other words, the data that you import is in ascending order, or you want it in sorted order. The first approach works very well if your data is sorted by column. There are a couple of ways you can approach how to delete these columns. If you import a lot of data, then deleting these columns can be a bother. When importing information from an external source, it is possible that the data will contain blank columns-columns with nothing in them.