EXCEl条件隐藏

来源:百度知道 编辑:UC知道 时间:2024/05/26 05:46:38
Private Sub Worksheet_Change(ByVal Target As Range)
A = Target.Row
If WorksheetFunction.CountIf(Range(A & ":" & A), 0) > 0 Then
Range(A & ":" & A).Select
Selection.EntireRow.Hidden = True
End If
End Sub
上面能实现某行内任意单元格为0,自动隐藏该行.
请问如何修改能规定比如任意一行,B列数字为0时隐藏该行?
谢谢

Alt+F11打开VBA编辑器复制如下代码
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.EntireRow.Cells(1, 2) = 0 And Target.EntireRow.Cells(1, 2) <> "" Then
Target.EntireRow.Hidden = True
End If
End Sub
运行代码即可
If Target.EntireRow.Cells(1, 2) = 0 And Target.EntireRow.Cells(1, 2) <> "" Then
Target.EntireRow.Hidden = True
这段代码的意思是,如果B列数字等于0或者为空时隐藏,去掉And Target.EntireRow.Cells(1, 2) <> "" 就是B列数字等于0时隐藏

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.EntireRow.Cells(1, 2) = 0 And Target.EntireRow.Cells(1, 2) <> "" Then
Target.EntireRow.Hidden = True
End If
End Sub

'不加上<>"",B列是空的时候也会隐藏

Private Sub Worksheet_Change(ByVal Target As Range)
Dim A As Integer
A = Target.Row
If WorksheetFunction.CountIf(Cells(A, 2), 0) >