I use the following code to hide rows which contain a specific value in a cell.
In the code below the row will be hidden when the value 1 is placed in any row in column E.
This is exactly what I need, although I want to have the option to hide and unhide the rows.
For example when entering a specific value in another cell like: in A1 the word hide or unhide to hide or show all rows.
How do I extend the script below to achieve this ?
Private Sub Worksheet_Calculate()
Dim LastRow As Long, c As Range
Application.EnableEvents = False
LastRow = Cells(Cells.Rows.Count, "E").End(xlUp).Row
On Error Resume Next
For Each c In Range("E1:E" & LastRow)
If c.Value = 1 Then
c.EntireRow.Hidden = True
ElseIf c.Value = 2 Then
c.EntireRow.Hidden = False
End If
Next
On Error GoTo 0
Application.EnableEvents = True
End Sub
Bookmarks