如何根据单元格值隐藏行?

问题描述 投票:1回答:1

我正在尝试让单元格A21包含一个介于0-10之间的整数,其中0表示22-31之间没有行,1表示22行,2表示22和23行,3表示22,23和24等,等等。 >

Private Sub Worksheet_Calculate()
Dim GenRequire As Integer
GenRequire = Range("A21").Value

Rows("22:31").EntireRow.Hidden = True
Select Case GenRequire
    Case Is = 0: Rows("22:31").EntireRow.Hidden = True 'No Rows shown
    Case Is = 1: Rows("22:22").EntireRow.Hidden = False '1st Row shown
    Case Is = 2: Rows("22:23").EntireRow.Hidden = False '1-2 rows shown
    Case Is = 3: Rows("22:24").EntireRow.Hidden = False '1-3 rows shown
    Case Is = 4: Rows("22:25").EntireRow.Hidden = False '1-4 rows shown
    Case Is = 5: Rows("22:26").EntireRow.Hidden = False '1-5 rows shown
    Case Is = 6: Rows("22:27").EntireRow.Hidden = False '1-6 rows shown
    Case Is = 7: Rows("22:28").EntireRow.Hidden = False '1-7 rows shown
    Case Is = 8: Rows("22:29").EntireRow.Hidden = False '1-8 rows shown
    Case Is = 9: Rows("22:30").EntireRow.Hidden = False '1-9 rows shown
    Case Is = 10: Rows("22:31").EntireRow.Hidden = False '1-10 rows shown
End Select
End Sub

我在Case Is = 10:上遇到错误,

运行时错误1004:应用程序定义的错误或对象定义的错误。

我的Excel版本有Office 365。

我正在尝试让单元格A21包含一个介于0-10之间的整数,其中0表示22-31之间没有行,1表示22行,2表示22和23行,3表示22,23和24,等等。子...

excel vba hide rows
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.