• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to find dynamically a empty column and delete using VBA?

Vijaychitra
Do You refer based Your sample file columns from A to G which has 'headers'?
There are many empty columns after G-column.
Do You have an idea to delete whole column?
How ( if columns A-G ):
#1 find the last used column
#2 check columns one-by-one from the last column (#1) to the 1st column
... if it's empty ( or there could be something in the 1st row ) then delete it
 
According to the attachment a VBA demonstration for a beginner starters :​
Code:
Sub Demo1()
        Dim C%
        Application.ScreenUpdating = False
    With [A1].CurrentRegion.Columns
        For C = .Count To 1 Step -1
            If Application.CountA(.Item(C)) < 2 Then .Item(C).Delete
        Next
    End With
        Application.ScreenUpdating = True
End Sub
Do you like it ? So thanks to click on bottom right Like !​
 
The code deletes all columns with values...I need to delete only empty column between A:D

I'm looking for a code -

Get the total column in current sheet, iterates on every column, find if the cells in each column is empty or not.
If cells in the column is empty, then delete the column.

In this table - I need to delete the column B & D.

ABCD
14
 
Vijaychitra
What was expected result to Your sample file #1 reply?
= which columns would be there after run Your missing code?
Or
Is #5 reply something different than Your original?
... if so then try to modify < 2 to < 1.

#5 reply ... are those A, B, C, D headers too?
 
A, B, C, D are headers names.

I need to find the count of columns names in the sheet. - Column Count = 4
Need to find columns which have empty data in columns (excluding column header name) - Header 3 column is empty
If a column header have empty data, we need to delete the column. - " Header 3" column needs deletion

Before Running the Macro
Header 1Header 2Header 3Header 4
36
557

After Running the Macro
Header 1Header 2Header 4
36
557
 
According to the attachment a VBA demonstration for a beginner starters :​
Code:
Sub Demo1()
        Dim C%
        Application.ScreenUpdating = False
    With [A1].CurrentRegion.Columns
        For C = .Count To 1 Step -1
            If Application.CountA(.Item(C)) < 2 Then .Item(C).Delete
        Next
    End With
        Application.ScreenUpdating = True
End Sub
Do you like it ? So thanks to click on bottom right Like !​

Thanks It worked Perfect.. Apologies for the delay...
 
Back
Top