anonymous userMillot-6866
Try the following code
Sub HideRowsUboveAndBelowZero()
Dim rngToProcess As Range
Dim rng As Range
Dim rngRowsToHide As Range
With Worksheets("Sheet1") 'Edit "Sheet1" to your sheet name
'Following line assumes column headers in row 1 so commences row 2
Set rngToProcess = .Range(.Cells(2, "A"), .Cells(.Rows.Count, "A").End(xlUp))
For Each rng In rngToProcess
If rng.Value = 0 Then
If rngRowsToHide Is Nothing Then
If rng.Row < 3 Then 'Less than row 3 do not hide column header
Set rngRowsToHide = .Range(.Cells(rng.Row, rng.Column), .Cells(rng.Row + 1, rng.Column))
Else
Set rngRowsToHide = .Range(.Cells(rng.Row - 1, rng.Column), .Cells(rng.Row + 1, rng.Column))
End If
Else
Set rngRowsToHide = Union(rngRowsToHide, .Range(.Cells(rng.Row - 1, rng.Column), .Cells(rng.Row + 1, rng.Column)))
End If
End If
Next rng
End With
rngRowsToHide.Rows.EntireRow.Hidden = True
End Sub