Unhide rows based on a numeric value in a cell

By : ongcaps
Source: Stackoverflow.com

I am trying to create Worksheet_Change() event to unhide rows based on the numeric value of one cell.

I have a table B13:B513. I want to unhide a number of rows equal to the value in C7. For example, if C7 = 10, then B13:B22 will unhide and the rest will still be hidden.

I have seen several ways of doing something similar but using "case" for each option. In my case I have 500 options. I am sure there is a more efficient way of doing this.

I am using Excel 2010.

Thanks in advance!


By : ongcaps


The code below on Worksheet_Change() event, will run only if the user changes the value in Cell "C7", you can modify it easily in the code (it is commeneted at which line).

The code wil unhide the number of rows specified starting from row 13 (according to Range 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
By : Shai Rado

This video can help you solving your question :)
By: admin