我有一张 Excel 工作表,我试图在其中设置多个条件来隐藏行。其中两个条件是如果特定单元格等于 0,则隐藏某些行;其中一个条件是如果特定单元格包含特定单词,则隐藏某些行;最后,如果特定列中为零,则隐藏行。当我单独执行时,它似乎有效,但我似乎无法使它共同工作。某些行可以包含在多个条件中。请注意,我在这方面很菜鸟。
以下是我尝试过的:
Sub Worksheet_Change(ByVal Target As Range)
Dim xRg As Range
Dim R2 As Range
Dim R3 As Range
Dim R1 As Range
Set R1 = Union(Rows("61:61"), Rows("68:69"), Rows("72:72"), Rows("91:106"), Rows("117:125"), Rows("144:155"), Rows("157:158"), Rows("164:164"), Rows("166:166"))
Set R2 = Union(Rows("49:52"), Rows("65:129"))
Set R3 = Union(Rows("53:57"), Rows("130:161"))
Application.ScreenUpdating = False
For Each xRg In Range("E8:E153")
If xRg.Value = 0 Then
xRg.EntireRow.Hidden = True
Else
xRg.EntireRow.Hidden = False
End If
Next xRg
If Range("E$15").Value = 0 Then
R3.EntireRow.Hidden = True
Else
R3.EntireRow.Hidden = False
End If
If Range("E$14").Value = 0 Then
R2.EntireRow.Hidden = True
Else
R2.EntireRow.Hidden = False
End If
If Range("B$3").Value = "USD" Then
R1.EntireRow.Hidden = True
Else
R1.EntireRow.Hidden = False
End If
Application.ScreenUpdating = True
End Sub