我正在尝试在Excel中使用以下代码,但它无效。 Cell AE25是指使用数据验证从列表中提取数字1-8的单元格。
Select Case Range("AE25").Value
Case 1
Range("A26:A28").EntireRow.Hidden = False
Case 2
Range("A26:A29").EntireRow.Hidden = False
Case 3
Range("A26:A30").EntireRow.Hidden = False
Case 4
Range("A26:A31").EntireRow.Hidden = False
Case 5
Range("A26:A32").EntireRow.Hidden = False
Case 6
Range("A26:A33").EntireRow.Hidden = False
Case 7
Range("A26:A34").EntireRow.Hidden = False
Case 8
Range("A26:A35").EntireRow.Hidden = False
End Select
任何帮助都将不胜感激。
答案 0 :(得分:1)
将此代码粘贴到您的数据所在的工作表的模块中,例如你有'Sheet1'中的数据,然后将其粘贴到'Sheet1'类模块。 HTH
Private Sub Worksheet_Change(ByVal Target As Range)
' AE25
If (Not Intersect(Target, Range("AE25")) Is Nothing) Then
Select Case Target.Value
Case 1
Range("A26:A28").EntireRow.Hidden = False
Case 2
Range("A26:A29").EntireRow.Hidden = False
Case 3
Range("A26:A30").EntireRow.Hidden = False
Case 4
Range("A26:A31").EntireRow.Hidden = False
Case 5
Range("A26:A32").EntireRow.Hidden = False
Case 6
Range("A26:A33").EntireRow.Hidden = False
Case 7
Range("A26:A34").EntireRow.Hidden = False
Case 8
Range("A26:A35").EntireRow.Hidden = False
Case Else
' hide all rows 26-35 if value is not equal to 1-8
Range("A26:A35").EntireRow.Hidden = True
End Select
End If
' Z40
If (Not Intersect(Target, Range("Z40")) Is Nothing) Then
Select Case Target.Value
Case "PowerPoint", "Verbal"
Range("A41").EntireRow.Hidden = False
Case "None"
Range("A41").EntireRow.Hidden = True
Case Else
End Select
End If
End Sub