Auto Delete Columns in a Macro that are Blank

  • Thread starter Thread starter dkeglor
  • Start date Start date
D

dkeglor

Hello! I have a very large spreadsheet that I have created a Macro to format
and formulate. I can't seem to find the correct coding to put into the macro
to search each and every column and get it to auto delete the column if it is
blank (contains no data). Can someone help me with this?
 
Option Explicit
Sub Testme()

dim iCol as long
dim Wks as worksheet

set wks = worksheets("somenamehere")

with wks
for icol = .usedrange.columns(.usedrange.columns.count).column _
to 1 step -1
if application.counta(.columns(icol)) > 0 then
'there's something in that column, skip it
else
.columns(icol).delete
end if
next icol
end with

end sub
 
Back
Top