简体   繁体   中英

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
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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM