Link to home
Start Free TrialLog in
Avatar of ca1358
ca1358

asked on

Hide Column if no data in Cell below

I have a excel spreadsheet and the spreadsheet has Headings in row 1.  
What I need, on open if there is a Heading in row 1 but the cells below have no data then to hide that column.

Any help would greatly be appreciated.
ASKER CERTIFIED SOLUTION
Avatar of StephenJR
StephenJR
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ardhendu Sarangi
Hi,
Can you try this code -

Sub HideME()
    Set ws = ActiveSheet ' SELECT CURRENT SHEET
    Set Rng = ws.Range("A1:ZZ65536") ' DEFINE RANGE
    For Each Col In Rng.Columns ' START SEARCHING THE RANGE FOR EMPTY COLUMNS
        'MsgBox (Mid(Col.Address, 2, 1))
        'MsgBox (Cells(65536, Mid(Col.Address, 2, 1)).End(xlUp).Row)
        If Cells(65536, Mid(Col.Address, 2, 1)).End(xlUp).Row = 1 Then
            Rng.Columns(Col.Column).EntireColumn.Hidden = True ' Hide COlumn if this is empty
        End If
    Next Col
End Sub

Open in new window


Thanks,
Ardhendu
Avatar of ca1358
ca1358

ASKER

Thank you