Bonnie
Bonnie

Reputation: 13

Hiding Rows Based on Information in Two Different Columns

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

Upvotes: 1

Views: 2282

Answers (1)

Dr. belisarius
Dr. belisarius

Reputation: 61016

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!

Upvotes: 1

Related Questions