+ Reply to Thread
Results 1 to 7 of 7

Problem with a macro to hide rows equal to zero ot empty

  1. #1
    Forum Contributor
    Join Date
    03-18-2013
    Location
    Bulgaria
    MS-Off Ver
    Excel 2010
    Posts
    139

    Problem with a macro to hide rows equal to zero ot empty

    Hey guys,

    I have this macro to hide any row that has all zeroes or blank spaces. Or in my case - Don't hide the row if there is a digit different than 0 or blank space on a cell in any column from B to E:

    Option Explicit

    Public Sub HideRows()
    Dim ws As Worksheet
    Dim cell As Range

    Application.ScreenUpdating = False

    For Each ws In ThisWorkbook.Worksheets
    'It will hide all the rows if any of the cell contain a 0 in it
    For Each cell In ws.Range("B1:E43")
    cell.EntireRow.Hidden = (cell.Value = "0") Or (cell.Value = "")
    Next cell

    Next ws

    Application.ScreenUpdating = True

    End Sub

    It hides most of the rows, however it also hides rows with numbers other than 0 or blank on it. I have attached an excerpt from the file I work on.
    Where is the error in it ?

    Thank you very much in advance!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Problem with a macro to hide rows equal to zero ot empty

    Why do you have code for multiple worksheets? Do you actually have more than one sheet you need this to work on?

  3. #3
    Forum Contributor
    Join Date
    03-18-2013
    Location
    Bulgaria
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: Problem with a macro to hide rows equal to zero ot empty

    Yes, I have multiple sheets in there. In your example if column B row 5 is 0, but Column C row 5 is 100,000 - this row shouldn't be hidden. Only rows that all four columns are either 0 or blank should be hidden.

  4. #4
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Problem with a macro to hide rows equal to zero ot empty

    Thanks for the clarification. Try:

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    03-18-2013
    Location
    Bulgaria
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: Problem with a macro to hide rows equal to zero ot empty

    This is awesome, thank you very much for your effort and help. One last question:
    There are rows in the beginning that I don't want to hide, as well as in the end of the file (because they are text and table headers).
    I want it to "check to hide rows" only for rows between 45 and 678. How do I adjust the macro to accommodate that?

  6. #6
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Problem with a macro to hide rows equal to zero ot empty

    Like this:

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    03-18-2013
    Location
    Bulgaria
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: Problem with a macro to hide rows equal to zero ot empty

    Works like a charm. Thank you for your help stnkynts!

+ 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