Delete Column if entire column is empty

SSmith1392

New Member
Joined
Feb 3, 2016
Messages
1
I have a spreadsheet without 40 columns and 100 rows where information is imported from a Microsoft Access file each day. Depending on the day certain columns are completely empty while others are filled. I have created a button on my spreadsheet and would like to link a macro to that button that would delete the entire column if each row within that column is empty. I have found some codes within the forum, but I can't seem to get any of them to work. Thanks in advance.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
I didnt test but try something like...

Code:
For i = whatever to 1 Step -1 'count backwards since deleting columns that you are iterating
    If IsEmpty(Columns(i).Value2) Then Columns(i).Delete
Next i

double check syntax i could be wrong but IsEmpty with the entire range inside it might be good enough to detect if the column is empty, what have you tested?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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
Back
Top