Hiding rows with zero sum value

M

Mike

I would like to revise my Macro (below) so that I include additonal rows to
hide if the value is zero sum. I don't know how to add rows that are not
consecutive, specifically, how do I add the following rows to my Macro :
C123, C124 & C132?

Sub HidePurchaseZero()

On Error Resume Next
With Range("C92:C115")
..EntireRow.Hidden = False
For i = 1 To .Rows.Count
If WorksheetFunction.Sum(.Rows(i)) = 0 Then
..Rows(i).EntireRow.Hidden = True
End If
Next i
End With


End Sub



Thanks in advance for your help
 
G

Gary''s Student

Try:

Sub HidePurchaseZero()
Dim r As Range
On Error Resume Next
Set r = Union(Range("C92:C115"), Range("C123:C124"), Range("C132"))
r.EntireRow.Hidden = False
For Each rr In r
If WorksheetFunction.Sum(rr.EntireRow) = 0 Then
rr.EntireRow.Hidden = True
End If
Next
End Sub
 
M

Mike

Thanks, unfortunately it doesn't seem to work and actually disables the
entire Macro? Any other possible suggestions?

Mike
 
M

Mike

Hi Jerek

Thanks for trying to help, unfortunately it didn't work. For some reason, it
did not incorporate the additonal rows I needed for it to incorporate, any
other ideas?

- Mike
 
G

Gary''s Student

My simple tests show no problems. What are you seeing??

Try running the macro on a completely empty worksheet. The indicated rows
should loose visiblity.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top