簡體   English   中英

根據單元格中的數值取消隱藏行

[英]Unhide rows based on a numeric value in a cell

我正在嘗試創建Worksheet_Change()事件以根據一個單元格的數值取消隱藏行。

我有一張桌子B13:B513 我想取消隱藏等於C7中的值的行數。 例如,如果C7 = 10,則B13:B22將取消隱藏,其余部分仍將隱藏。

我已經看到了幾種做類似事情的方法,但每個選項使用“case”。 在我的情況下,我有500個選項。 我相信有一種更有效的方法。

我正在使用Excel 2010。

提前致謝!

丹尼爾

Worksheet_Change()事件下面的代碼只有在用戶更改單元格“ C7 ”中的值時才會運行,您可以在代碼中輕松修改它(它被標記在哪一行)。

代碼將取消隱藏從第13行開始指定的行數(根據范圍B13:B513

Private Sub Worksheet_Change(ByVal Target As Range)

Dim WatchRange                  As Range
Dim IntersectRange              As Range
Dim Numof_UnhideRows            As Long
Dim UnhideRowStart              As Long


' if you want to unhide the rows in Range(B13:B513) only when someone canges the vlues in C7
Set WatchRange = Range("C7")

' starting unhiding number of rows starting for row 13
UnhideRowStart = 13

Set IntersectRange = Intersect(Target, WatchRange)

If Not IntersectRange Is Nothing Then
    If IsNumeric(Target.Value) Then
        Numof_UnhideRows = Target.Value
        Rows(UnhideRowStart & ":" & UnhideRowStart + Numof_UnhideRows - 1).EntireRow.Hidden = False

        MsgBox "Unhide a total of " & Numof_UnhideRows & " rows"
    Else
        MsgBox "Cell C7 doesn't contain a Numeric Value", vbCritical
    End If
Else
   'Do Nothing Spectacular

End If

End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM