tags:

views:

13

answers:

1

Hi, I need to be able to hide a row if the numbers in column "c" and in column "d" are zero. I the below code works but stops after looping through only 4 rows of data. There is nothing different between the data so I don't know why it stops. Can someone please help me? Thank you.

Sub Hide_Row_3()

' Hide_Row_3 Macro

Worksheets("Costs").Activate
Application.ScreenUpdating = False

Dim rCell As Range

For Each rCell In Range("c7:c18, d7:d18")
    If rCell = 0 And rCell(xright) = 0 Then
        rCell.EntireRow.Hidden = True
    Else
        rCell.EntireRow.Hidden = False
End If

Next rCell

Application.ScreenUpdating = True

End Sub
A: 
For Each rCell In Range("c7:c18")

is enough.

Edit>

The following loop works for me"

For Each rCell In Range("c7:c18")
    If rCell = 0 And rCell.Offset(0, 1) = 0 Then
        rCell.EntireRow.Hidden = True
    Else
       rCell.EntireRow.Hidden = False
End If

HTH!

belisarius
Hi Belisarius, I limited the code to column C but now the code is not running line by line. It is running continous, so that it is only hidding rows if the value of three continous cells are zero. Example is c7, d7, and c8. Can you tell me how to fix this? Thank you.
Bonnie
@Bonnie See my updated answer
belisarius
Thank you so much Belisarius. The code worked perfect!
Bonnie
@Bonnie Glad to hear that. You should accept the answer to indicate that ... and eventually vote it up too.
belisarius