Excel VBA? Delete Columns

I have a worksheet which is 150 columns by 22,000 rows. I know that some columns have never been used, but Size constrains my checking and deleting of the unused columns. Is there a way that I can test to see if a column has no values and then delete it, or all of them?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I'm assuming that each column has a heading. Is that right? So a column with a heading but 21,999 empty cells beneath it should be deleted?
JT8337Author Commented:
That is correct. I should have mentioned that.

pls try

Sub macro()

For Idx = Cells(1, Columns.Count).End(xlToLeft).Column To 1 Step -1
    If WorksheetFunction.CountA(Cells(2, Idx).Resize(22000, 1)) = 0 Then
        Cells(2, Idx).EntireColumn.Delete
    End If
End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JT8337Author Commented:
will try as soon as I am back in, within the hour. Thank you.
JT8337Author Commented:
Thank you. This is such a time saver
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.