我正在使用以下代码根据单元格值隐藏行:
Sub HideN()
Dim RowCnt As Long, uRng As Range
BeginRow = 8
EndRow = 232
ChkCol = 6
For RowCnt = BeginRow To EndRow
If Cells(RowCnt, ChkCol).Value = 0 Then
If uRng Is Nothing Then
Set uRng = Cells(RowCnt, ChkCol)
Else
Set uRng = Union(uRng, Cells(RowCnt, ChkCol))
End If
End If
Next RowCnt
If Not uRng Is Nothing Then uRng.EntireRow.Hidden = True
End Sub
如果我还想取消隐藏单元格值为1的行,我还需要修改什么?
提前致谢!
MD
答案 0 :(得分:3)
这将隐藏所有0并取消隐藏所有其他内容。
/usr/bin/time -v
当然,你可以使用过滤器做同样的事情。
答案 1 :(得分:0)
你可以添加一个额外的If
语句,不是吗?:
Sub HideN()
Dim RowCnt As Long, uRng As Range
BeginRow = 8
EndRow = 232
chkcol = 6
For RowCnt = BeginRow To EndRow
If Cells(RowCnt, chkcol).Value = 0 Then
If uRng Is Nothing Then
Set uRng = Cells(RowCnt, chkcol)
Else
Set uRng = Union(uRng, Cells(RowCnt, chkcol))
End If
End If
If Cells(RowCnt, chkcol).Value = 1 Then ' This is the new line to add
Rows(RowCnt).EntireRow.Hidden = False
End If
Next RowCnt
If Not uRng Is Nothing Then uRng.EntireRow.Hidden = True
End Sub