A
Ayo
What I am trying to do is as follows:
When I change the value in cell E3 or E79, I want all the rows between
("B5:B77") and ("B81:B153") that do not have the same values as in cell E3 or
E79 to be hidden. Right now I am getting an error on this line:
If Not rngAll Is Nothing Then rngAll.EntireRow.Hidden = True
Any help will be greatly appreiciated.Thanks.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range, rngAll As Range
Application.ScreenUpdating = False
If Target.Address = "$E$3" Or Target.Address = "$E$79" Then
Me.Range("E3").Value = Target.Value
Me.Range("E79").Value = Target.Value
Application.EnableEvents = False
For Each c In Me.Range("B5:B77").Cells
If c.Value <> Target.Value Then
If rngAll Is Nothing Then
Set rngAll = c
Else
Set rngAll = Union(rngAll, c)
End If
End If
Next c
If Not rngAll Is Nothing Then rngAll.EntireRow.Hidden = True
For Each c In Me.Range("B81:B153").Cells
If c.Value <> Target.Value Then
If rngAll Is Nothing Then
Set rngAll = c
Else
Set rngAll = Union(rngAll, c)
End If
End If
Next c
If Not rngAll Is Nothing Then rngAll.EntireRow.Hidden = True
Application.EnableEvents = True
End If
End Sub
When I change the value in cell E3 or E79, I want all the rows between
("B5:B77") and ("B81:B153") that do not have the same values as in cell E3 or
E79 to be hidden. Right now I am getting an error on this line:
If Not rngAll Is Nothing Then rngAll.EntireRow.Hidden = True
Any help will be greatly appreiciated.Thanks.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range, rngAll As Range
Application.ScreenUpdating = False
If Target.Address = "$E$3" Or Target.Address = "$E$79" Then
Me.Range("E3").Value = Target.Value
Me.Range("E79").Value = Target.Value
Application.EnableEvents = False
For Each c In Me.Range("B5:B77").Cells
If c.Value <> Target.Value Then
If rngAll Is Nothing Then
Set rngAll = c
Else
Set rngAll = Union(rngAll, c)
End If
End If
Next c
If Not rngAll Is Nothing Then rngAll.EntireRow.Hidden = True
For Each c In Me.Range("B81:B153").Cells
If c.Value <> Target.Value Then
If rngAll Is Nothing Then
Set rngAll = c
Else
Set rngAll = Union(rngAll, c)
End If
End If
Next c
If Not rngAll Is Nothing Then rngAll.EntireRow.Hidden = True
Application.EnableEvents = True
End If
End Sub