2

我正在尝试在 Excel 中使用以下代码,但它不起作用。单元格 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

任何帮助,将不胜感激。

4

1 回答 1

3

将此代码粘贴到数据所在的工作表模块中,例如,您在“Sheet1”中有数据,然后将其粘贴到“Sheet1”类模块。高温高压

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

在此处输入图像描述

于 2013-08-06T08:29:35.483 回答