我没有VBA的经验,一直试图通过谷歌我的方式通过一些功能,我想。当前的目标是根据另一个单元格的输入隐藏一行。这部分工作,但如果数据被删除,我得到的错误。代码在下面。
Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.Activate
If Not Application.Intersect(Range("U8:Y8"), Range(Target.Address)) Is Nothing Then
Select Case Target.Value
Case Is = "Owner": Rows("11:11").EntireRow.Hidden = True
Case Is = "Renter": Rows("11:11").EntireRow.Hidden = False
Case Is = "": Rows("11:11").EntireRow.Hidden = False
End Select
End If
If Not Application.Intersect(Range("U8:Y8"), Range(Target.Address)) Is Nothing Then
Select Case Target.Value
Case Is = "Renter": Rows("18:18").EntireRow.Hidden = True
Case Is = "Owner": Rows("18:18").EntireRow.Hidden = False
Case Is = "": Rows("18:18").EntireRow.Hidden = False
End Select
End If
If Not Application.Intersect(Range("G22:K22"), Range(Target.Address)) Is Nothing Then
Select Case Target.Value
Case Is = "Mail": Rows("23:23").EntireRow.Hidden = True
Case Is = "E-Billing": Rows("23:23").EntireRow.Hidden = False
Case Is = "": Rows("23:23").EntireRow.Hidden = False
End Select
End If
End Sub
字符串
最初的范围只是“U8”和“G22”,我想如果我包括每个合并区域的全部范围,它会工作,但没有。
1条答案
按热度按时间ctehm74n1#
当 * 输入 * 一个值到一个合并的单元格中时,它会触发带有单个单元格
Target
(即Change
)的Change
事件。Target.Cells.CountLarge = 1
),但是当从合并单元格中 * 删除 * 一个值时,它会触发多单元格Target
(在本例中为Target.Cells.CountLarge = 5
),因此您需要在事件处理代码中说明这一点。字符串