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.
Bookmarks