+ Reply to Thread
Results 1 to 4 of 4

Hide empty rows of shown columns

Hybrid View

  1. #1
    Registered User
    Join Date
    05-11-2012
    Location
    Calgary
    MS-Off Ver
    Excel 2003
    Posts
    6

    Hide empty rows of shown columns

    I have a worksheet with 10 rows and 10 columns.
    The rows contain values 0,1,and 2.
    The first column contains some names, the other columns contain just the values mentioned above.
    Three of the columns are hidden.
    What I want to do is look at the columns that are visible, look at the row values, and then hide any rows for which the sum of all values is 0.
    I've attached an excel file to better illustrate my pioint

    Forum.xlsx

  2. #2
    Valued Forum Contributor
    Join Date
    02-09-2012
    Location
    Mauritius
    MS-Off Ver
    Excel 2007
    Posts
    1,055

    Re: Hide empty rows of shown columns

    Hi

    Try this.. I hope this is what you wanted...

    Forum.xlsm
    Click *, if my suggestion helps you. Have a good day!!

  3. #3
    Registered User
    Join Date
    05-11-2012
    Location
    Calgary
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Hide empty rows of shown columns

    Hi - That totally does what I need. The thing that's missing, and that I cannot figure out, is how to do it dynamically.
    i.e., cycle through all columns, identify which ones are hidden, and then check to see if new rows should be hidden. At any given time, different columns may be hidden.

  4. #4
    Registered User
    Join Date
    05-11-2012
    Location
    Calgary
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Hide empty rows of shown columns

    Alright, i was able to put something together. Thought I'd share.

    In the part of my code where I hide columns, I added an array to register which columns are actually showing:
    Wks.Columns(Col.Column).Hidden = False
                            OpenArray(N) = "yes"
    At the end of my sheet I added a new logic to loop through all open columns and add up the cell values. If the cell value is 0 then I hide the row.
        ' now hide empty rows
        ' cycle through rows
        Set Rng = Wks.Range("C4:Z100")
        
        ' loop through rows
        R = 3
        For Each Row In Rng.Rows
            R = R + 1
            
            E = 0
            ' loop through active columns
            For x = LBound(OpenArray) To UBound(OpenArray)
                If OpenArray(x) <> "" Then
                    ' I now have the column letter, so I can check its value
                    E = E + Wks.Range("A1:Z100").Cells.Item(R, x)
                End If
            Next x
            If E = 0 Then
                ' hide this row
                Wks.Rows(R).Hidden = True
            Else
                'show this row
                Wks.Rows(R).Hidden = False
            End If
        Next Row
    Hopefully this will be of use to somebody else, too.

+ Reply to Thread

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