I have some information in rows 9 to 38. I need to hide these rows based on a cell value, for example A8:
If
A8=3then only show rows 9 to 11 out of 38if
A8=9then only show rows 9 to 18 out of 38If
A8=0then hide all rows from 9 to 38.
... and so on, only for rows 9 to 38.
This is my code so far:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim var As Variant
'Determine if change was made to cell A8
If Not Intersect(Target, Range("A8")) Is Nothing Then
'Get value
var = Range("A8").Value
var = var + 9
Debug.Print var
'Hide all rows
Rows("9:38").EntireRow.Hidden = True
For i = 9 To var
'Show Rows
Rows("9:i").EntireRow.Hidden = False
Debug.Print i
Next i
End If
End Sub