需要VBA /宏代码来隐藏列中包含0值的行

时间:2017-09-21 04:06:12

标签: vba excel-vba excel

如果来自B9:AF54和B60:AF129的任何单元格的值大于0,我只希望行可见。

例如,如果每个对应列的整行都为0,我希望它隐藏起来。如果行中的任何单元格的值为1或更高,我希望它们可见。

1 个答案:

答案 0 :(得分:0)

Sub HideRows()
Dim i As Long
Dim j As Long
Dim hide As Boolean
'loop through rows
For i = 9 To 54
    hide = True
    'loop in the row: B through AF column
    For j = 2 To 32
        'if we found value greater then zero, then we don't want to hide this row
        If Cells(i, j).Value > 0 Then
            hide = False
            Exit For
        End If
    Next j

    Rows(i).Hidden = hide
Next i

'loop thorugh second range
For i = 60 To 129
    hide = True
    'loop in the row: B through AF column
    For j = 2 To 32
        'if we found value greater then zero, then we don't want to hide this row
        If Cells(i, j).Value > 0 Then
            hide = False
            Exit For
        End If
    Next j

    Rows(i).Hidden = hide
Next i
End Sub