Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Column Hide Macro

Status
Not open for further replies.

DKyte

Technical User
Apr 18, 2003
4
0
0
US
I have an Excel spreadsheet that I am pulling data from Tab #2 to Tab #1 only if specified with a formula saying that I want the data to appear on Tab #1.

Once the data is populated in the columns on Tab #1, I often have blank columns.

Ex:
Alabama Blank Column Alaska Blank Column

I would like the Blank Column to automatically hide if it is not populated with data.

The twist: The blank column, however not populated with data, still has a formula in it asking it to search Tab #2. The formula didn't pull the data from Tab #2, but it still exists in the column.

Any advise on a macro to solve my problem would be appreciated.
 
Hi,

See if this might help...
Code:
Sub HideEmptyCols()
    With ActiveSheet.UsedRange
        For i = .Columns.Count + .Column - 1 To .Column Step -1
            bEmpty = True
            For Each r In .Range(Cells(.Row, i), Cells(.Rows.Count + .Row - 1, i))
                If r.Value <> &quot;&quot; Then
                    bEmpty = False
                    Exit For
                End If
            Next
            Columns(i).Hidden = bEmpty
        Next
    End With
End Sub
:)

Skip,
Skip@TheOfficeExperts.com
 
I will. I'm going to try this now. I'll post in a little bit if it worked or if I need more help. Thanks
 
Skip - Got it to work. Thanks so so much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top