Hide Row If Any Cell In It = 0

  • Thread starter Thread starter robzrob
  • Start date Start date
R

robzrob

Hello All

Searched high and low amongst the forums for this and found some close
solutions, but can't seem to make any work.

I have Rows 1-100 & Cols A-J all with formulas or text in them. If
the result of any of the formulas in any of the that range is 0, I
want the entire row hidden.

Cheers
 
Hi

Try this:

Sub aaa()
Dim targetRange As Range
Dim tRange As Range
Application.ScreenUpdating = False
Set targetRange = Range("A1:J100")
For Each r In targetRange.Rows
Set tRange = targetRange.Rows(r.Row)
For Each cell In tRange.Cells
If cell.Value = 0 Then
Rows(cell.Row).Hidden = True
Exit For
End If
Next
Next
Application.ScreenUpdating = True
End Sub

Regards,
Per
 
Sub HideThem()
Dim r As Range
Set r = Range("A1:J100").SpecialCells(xlCellTypeFormulas)
Set rHide = Nothing
For Each rr In r
If rr.Value = 0 Then
If rHide Is Nothing Then
Set rHide = rr
Else
Set rHide = Union(rHide, rr)
End If
End If
Next

If rHide Is Nothing Then
Else
rHide.EntireRow.Hidden = True
End If
End Sub
 
Hi

Try this:

Sub aaa()
Dim targetRange As Range
Dim tRange As Range
Application.ScreenUpdating = False
Set targetRange = Range("A1:J100")
For Each r In targetRange.Rows
    Set tRange = targetRange.Rows(r.Row)
    For Each cell In tRange.Cells
        If cell.Value = 0 Then
            Rows(cell.Row).Hidden = True
            Exit For
        End If
    Next
Next
Application.ScreenUpdating = True
End Sub

Regards,
Per

"robzrob" <[email protected]> skrev i meddelelsen






- Show quoted text -


Thanks. But it comes to a halt on: If cell.Value = 0 Then Perhaps I
should say that some of the cell values currently return #REF! (but
normally they would either be text or 0 or blank and also that I don't
want to test for blank or "", only 0.
 
Sub HideThem()
Dim r As Range
Set r = Range("A1:J100").SpecialCells(xlCellTypeFormulas)
Set rHide = Nothing
For Each rr In r
    If rr.Value = 0 Then
        If rHide Is Nothing Then
            Set rHide = rr
        Else
            Set rHide = Union(rHide, rr)
        End If
    End If
Next

If rHide Is Nothing Then
Else
    rHide.EntireRow.Hidden = True
End If
End Sub

--
Gary''s Student - gsnu201001








- Show quoted text -



Thanks. This hides the rows, then I can't seem to Unhide - they
appear to be deleted. And it's hiding rows with #REF! and blank in
them too - but I only want to test for 0.
 
I note from your reply to Per you have REF errors, this copes with those and
blank cells

Dim LastRow As Long
LastRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:J" & LastRow)
For Each c In MyRange.Rows
Set RowRange = MyRange.Rows(c.Row)
For Each cl In RowRange.Cells
If Not IsError(cl.Value) Then
If cl.Value <> "" And cl.Value = 0 Then
Rows(cl.Row).Hidden = True
Exit For
End If
End If
Next cl
Next c
End Sub


--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.
 
I note from your reply to Per you have REF errors, this copes with those and
blank cells

Dim LastRow As Long
LastRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:J" & LastRow)
For Each c In MyRange.Rows
    Set RowRange = MyRange.Rows(c.Row)
    For Each cl In RowRange.Cells
        If Not IsError(cl.Value) Then
        If cl.Value <> "" And cl.Value = 0 Then
            Rows(cl.Row).Hidden = True
            Exit For
        End If
        End If
    Next cl
Next c
End Sub

--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.








- Show quoted text -


Thanks - that's doing it great!
 
Back
Top