请帮我
如果单元格值为 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
它运行完美,但我希望代码也检查列K
(相同范围K9:K48
),如果一行中的两个单元格都是 0,则该行必须被隐藏。我该如何更改代码来做到这一点?
答案1
尝试这个:
....
For Each c In Range("I9:I48")
If (c.Value = 0 OR c.Offset(1,0).Value = 0) Then
c.EntireRow.Hidden = True
....