Delete columns where all cells are empty

RogerC

Well-known Member
Joined
Mar 25, 2002
Messages
533
My spreadsheet has 350 columns, many of which contain only a header. Other columns may contain both values and blank cells.

Is there a non-VBA method to find and delete all columns where there are only blank cells below the header?

The 'Go To... Blanks' method to find blank cells won't work, because I don't want blank cells deleted from columns where some cells have data.
 

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,566
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Thanks johnnyL.'s code (CountA(Columns(col)) = 1) doesn't catch completely empty columns. Try CountA(Columns(col)) <= 1 instead.

Your code seems to work with the exception of 5 columns. After running the macro the total number of columns went from 350 to 133. However, 5 columns within those 133 contain only Blank cells.

Of course, deleting them manually is manageable now, but do you have any idea why they would not have been deleted?
Johnny
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,144,236
Messages
5,723,169
Members
422,479
Latest member
Mr_Confused

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top