1

Please help me

I am using the following code to hide rows if cell values are 0:

Private Sub Worksheet_Calculate()
Dim LastRow As Long, c As Range
Application.EnableEvents = False
LastRow = Cells(Cells.Rows.Count, "I").End(xlUp).Row
On Error Resume Next
For Each c In Range("I9:I48")
   If c.Value = 0 Then
        c.EntireRow.Hidden = True
    ElseIf c.Value > 0 Then
        c.EntireRow.Hidden = False
    End If
Next
On Error GoTo 0
Application.EnableEvents = True
End Sub

It works perfectly, but I would like for the code to also check column K (the same range K9:K48) if both cells in a row are 0 then the row must be hidden. How can I change the code to do this?

2
  • The same range I9:I48 or K9:K48? ^^ Anyway, maybe it would be better to move your question to StackOverflow May 28, 2014 at 8:35
  • @duDE VBA questions are on-topic here as well, so no need to migrate.
    – Excellll
    May 30, 2014 at 21:05

1 Answer 1

1

Try this:

....
For Each c In Range("I9:I48")
   If (c.Value = 0 OR c.Offset(1,0).Value = 0) Then
        c.EntireRow.Hidden = True
        ....

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .