Results 1 to 6 of 6

How to hide all empty columns without including the column header

Threaded View

  1. #1
    Registered User
    Join Date
    11-09-2010
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    3

    How to hide all empty columns without including the column header

    I have a spreadsheet that will have column headers. But some of the columns will be empty. I need to determine which columns are empty, minus the column headers, and hide them all. I've tried several things but I'm sure I'm missing something.

    Sub HideEmptyCols()
        ' Deletes all empty columns on the active worksheet
        Dim iCol As Integer
        Dim wsSheet As Worksheet
     
        For Each wsSheet In Worksheets
            wsSheet.Select
            With wsSheet.UsedRange
                For iCol = .Column + .Columns.Count - 1 To 1 Step -1
                    If IsEmpty(Cells(65536, iCol)) And IsEmpty(Cells(1, iCol)) Then
                        If Cells(65536, iCol).End(xlUp).Row = 1 Then Columns(iCol).Hidden = True
                    MsgBox (iCol)
                    End If
                    MsgBox (iCol)
                Next iCol
            End With
        Next wsSheet
    End Sub
    Last edited by mkingsberry; 11-09-2010 at 12:06 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1