+ Reply to Thread
Results 1 to 18 of 18

Hide / Unhide rows where all cell values are ZERO

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Hide / Unhide rows where all cell values are ZERO

    Hi,

    I have a Worksheet with +25 sheets in it.
    Some sheets have 4,000 rows, most where the cell values in the enitre row ar zero.
    I'd like to have one button that will hide these rows and another to unhide them.

    Many thanks

  2. #2
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Hide / Unhide rows where all cell values are ZERO

    Sub test()
    
    Dim l As Long
    Dim lRow As Long
    
    lRow = Range("A" & Rows.Count).End(xlUp).Row
    
    For l = 1 To lRow
        If Application.WorksheetFunction.Sum(Rows(l)) = 0 Then
            Rows(l).Hidden = True
        End If
    Next l
        
    End Sub
    e/ Just realized you mentioned multiple sheets also. I will edit for all sheets.
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  3. #3
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Hide / Unhide rows where all cell values are ZERO

    Sub test()
    
    Dim ws As Worksheet
    Dim l As Long
    Dim lRow As Long
    
    For Each ws In Worksheets
        lRow = ws.Range("A" & Rows.Count).End(xlUp).Row
        For l = 1 To lRow
            If Application.WorksheetFunction.Sum(ws.Rows(l)) = 0 Then
                ws.Rows(l).Hidden = True
            End If
        Next l
    Next ws
        
    End Sub

  4. #4
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Re: Hide / Unhide rows where all cell values are ZERO

    Thank you for being so quick!

    Do you have one for the Unhide button?

    Much appreciated

  5. #5
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Hide / Unhide rows where all cell values are ZERO

    Unhide all? or only unhide rows that total to 0?

  6. #6
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Re: Hide / Unhide rows where all cell values are ZERO

    Ahhh I see ... both would have the same result

    I could quite easily record a macro that will unhide all rows

    Sometimes blinded by science

    Thank you for all your help!

  7. #7
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Hide / Unhide rows where all cell values are ZERO

    Glad to help.

    You can also try this:
    Sub test()
    Dim ws As Worksheet
    For Each ws In Worksheets
        ws.UsedRange.EntireRow.Hidden = False
    Next ws
    End Sub

  8. #8
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Re: Hide / Unhide rows where all cell values are ZERO

    Thank you, I will do!

  9. #9
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Re: Hide / Unhide rows where all cell values are ZERO

    Hi, is there a way to update the code or even my sheets so that lines where there is noting ae not hidden, else presentation is affected. Let me explain .. say I have

    Assets

    Liabilities

    Capital

    Expenses

    I don't want it to look like ..

    Assets
    Liabilities
    Capital
    Expenses

    Hope I make sense
    Ta

  10. #10
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Hide / Unhide rows where all cell values are ZERO

    I'm not sure I understand, you don't want the entire row hidden if what?

  11. #11
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Re: Hide / Unhide rows where all cell values are ZERO

    If there is nothing in that row

  12. #12
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Hide / Unhide rows where all cell values are ZERO

    Sorry I should have been more clear. I believe there are certain rows that you do not want hidden:
    Hi, is there a way to update the code or even my sheets so that lines where there is noting ae not hidden, else presentation is affected.
    Which are the rows that you never want hidden because they effect presentation if they are hidden?

  13. #13
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Re: Hide / Unhide rows where all cell values are ZERO

    I have rows with multiple columns that contain formulae, and in some of these rows all the values in the columns are zero - I want these hidden
    Some rows have absolutley nothing in them, they are left blank - I do not want these hidden

    Ta

  14. #14
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Hide / Unhide rows where all cell values are ZERO

    Ah. I understand. What column to the 0's start in?

  15. #15
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Re: Hide / Unhide rows where all cell values are ZERO

    Column D

    Could use something like ...(I'm a novice so I'm unsure)

    If Application.CountA(ActiveCell.EntireRow)=0 Then
    End IF
    Else Application.WorksheetFunction.Sum(Rows(l)) = 0 Then
    Rows(l).Hidden = True
    End If

  16. #16
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Re: Hide / Unhide rows where all cell values are ZERO

    Column D

    Could use something like ...(I'm a novice so I'm unsure)

    If Application.CountA(ActiveCell.EntireRow)=0 Then
    End IF
    Else Application.WorksheetFunction.Sum(Rows(l)) = 0 Then
    Rows(l).Hidden = True
    End If

  17. #17
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Hide / Unhide rows where all cell values are ZERO

    try
    Sub test()
    
    Dim ws As Worksheet
    Dim l As Long
    Dim lRow As Long
    
    For Each ws In Worksheets
        lRow = ws.Range("A" & Rows.Count).End(xlUp).Row
        For l = 1 To lRow
            If ws.Range("D" & l).Value <> "" Then
                If Application.WorksheetFunction.Sum(ws.Rows(l)) = 0 Then
                    ws.Rows(l).Hidden = True
                End If
            End If
        Next l
    Next ws
        
    End Sub

  18. #18
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Re: Hide / Unhide rows where all cell values are ZERO

    Awesome! That's it!

    Thank you very much

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Checkbox VBA - Hide/Unhide Rows and/or Columns based on cell values
    By gravy258 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-21-2013, 05:39 PM
  2. hide/unhide rows based on multiple cell values
    By saninmelbourne in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-20-2012, 06:45 PM
  3. [SOLVED] Using Value in Cell to hide/unhide rows
    By maayub15 in forum Excel Formulas & Functions
    Replies: 29
    Last Post: 03-15-2012, 02:23 AM
  4. Hide/Unhide rows based on 3 cells values
    By bimmer5dude in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-24-2008, 11:02 AM
  5. Hide/unhide rows with zero values
    By sujittalukder in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 06-22-2007, 02:54 AM

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