Results 1 to 5 of 5

Hide row if cell is a certain value, with unhide toggle option

Threaded View

  1. #1
    Registered User
    Join Date
    06-08-2007
    Posts
    22

    Hide row if cell is a certain value, with unhide toggle option

    Hi, I'm trying to configure a button in a worksheet to look at a range of data, and if the the value in the A column is "xxxxx" it will hide the entire row. Clicking this row again will display all of the rows again.

    I have so far:
    Sub HideItem()
    ActiveSheet.Unprotect
        If Range("8:207").EntireRow.Hidden = True Then
        Range("8:207").EntireRow.Hidden = False
        Else
        For Each Cell In Range("A8:A207")
            If Cell.Value = "xxxxx" Then Cell.EntireRow.Hidden = True
            Next Cell
        End If
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
    End Sub
    This almost works, except that if anything other than "xxxxx" is entered in a cell in the A column, it won't unhide.

    When I try this:

    Sub HideItem()
    ActiveSheet.Unprotect
        For Each Row In Range("8:207")
            If Row.EntireRow.Hidden = True Then Row.EntireRow.Hidden = False
            Next Row
        Else
        For Each Cell In Range("A8:A207")
            If Cell.Value = "xxxxx" Then Cell.EntireRow.Hidden = True
            Next Cell
        End If
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
    End Sub
    I get the "Else without If" error. How can I get this to work? Can I not use two For Each... commands with a conditional hierarchy?

    Please help! Thanks in advance.
    Last edited by stir-crazy; 01-16-2008 at 06:11 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