Using a cell on another worksheet to run my code?

Andy C 1987

New Member
Joined
Oct 24, 2023
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I have the below code which works exactly how i want it to on this particular worksheet however i want the cell i another worksheet to be the reference cell which changes depending on some other formulas runnning?

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.Activate
If Not Application.Intersect(Range("A4"), Range(Target.Address)) Is Nothing Then
        Select Case Target.Value
        Case Is = "0":  Rows("5:18").EntireRow.Hidden = True
                        Rows("19:34").EntireRow.Hidden = True
                        Rows("35:48").EntireRow.Hidden = True
                        Rows("49:64").EntireRow.Hidden = True
                        Rows("65:78").EntireRow.Hidden = True
                        Rows("79:94").EntireRow.Hidden = True
                        Rows("95:108").EntireRow.Hidden = True
                        Rows("109:124").EntireRow.Hidden = True
                        Rows("125:138").EntireRow.Hidden = True
                        Rows("139:154").EntireRow.Hidden = True
                        Rows("155:168").EntireRow.Hidden = True
                        Rows("169:184").EntireRow.Hidden = True
                        Rows("185:198").EntireRow.Hidden = True
                        Rows("199:214").EntireRow.Hidden = True
                        Rows("215:228").EntireRow.Hidden = True
                        Rows("229:244").EntireRow.Hidden = True
                        Rows("245:258").EntireRow.Hidden = True
                        Rows("259:274").EntireRow.Hidden = True
                        Rows("275:288").EntireRow.Hidden = True
                        Rows("289:302").EntireRow.Hidden = True
        Case Is = "1":  Rows("5:18").EntireRow.Hidden = False
                        Rows("19:34").EntireRow.Hidden = True
                        Rows("35:48").EntireRow.Hidden = True
                        Rows("49:64").EntireRow.Hidden = True
                        Rows("65:78").EntireRow.Hidden = True
                        Rows("79:94").EntireRow.Hidden = True
                        Rows("95:108").EntireRow.Hidden = True
                        Rows("109:124").EntireRow.Hidden = True
                        Rows("125:138").EntireRow.Hidden = True
                        Rows("139:154").EntireRow.Hidden = True
                        Rows("155:168").EntireRow.Hidden = True
                        Rows("169:184").EntireRow.Hidden = True
                        Rows("185:198").EntireRow.Hidden = True
                        Rows("199:214").EntireRow.Hidden = True
                        Rows("215:228").EntireRow.Hidden = True
                        Rows("229:244").EntireRow.Hidden = True
                        Rows("245:258").EntireRow.Hidden = True
                        Rows("259:274").EntireRow.Hidden = True
                        Rows("275:288").EntireRow.Hidden = True
                        Rows("289:302").EntireRow.Hidden = True
        Case Is = "2":  Rows("5:18").EntireRow.Hidden = False
                        Rows("19:34").EntireRow.Hidden = False
                        Rows("35:48").EntireRow.Hidden = True
                        Rows("49:64").EntireRow.Hidden = True
                        Rows("65:78").EntireRow.Hidden = True
                        Rows("79:94").EntireRow.Hidden = True
                        Rows("95:108").EntireRow.Hidden = True
                        Rows("109:124").EntireRow.Hidden = True
                        Rows("125:138").EntireRow.Hidden = True
                        Rows("139:154").EntireRow.Hidden = True
                        Rows("155:168").EntireRow.Hidden = True
                        Rows("169:184").EntireRow.Hidden = True
                        Rows("185:198").EntireRow.Hidden = True
                        Rows("199:214").EntireRow.Hidden = True
                        Rows("215:228").EntireRow.Hidden = True
                        Rows("229:244").EntireRow.Hidden = True
                        Rows("245:258").EntireRow.Hidden = True
                        Rows("259:274").EntireRow.Hidden = True
                        Rows("275:288").EntireRow.Hidden = True
                        Rows("289:302").EntireRow.Hidden = True
        Case Is = "3":  Rows("5:18").EntireRow.Hidden = False
                        Rows("19:34").EntireRow.Hidden = False
                        Rows("35:48").EntireRow.Hidden = False
                        Rows("49:64").EntireRow.Hidden = True
                        Rows("65:78").EntireRow.Hidden = True
                        Rows("79:94").EntireRow.Hidden = True
                        Rows("95:108").EntireRow.Hidden = True
                        Rows("109:124").EntireRow.Hidden = True
                        Rows("125:138").EntireRow.Hidden = True
                        Rows("139:154").EntireRow.Hidden = True
                        Rows("155:168").EntireRow.Hidden = True
                        Rows("169:184").EntireRow.Hidden = True
                        Rows("185:198").EntireRow.Hidden = True
                        Rows("199:214").EntireRow.Hidden = True
                        Rows("215:228").EntireRow.Hidden = True
                        Rows("229:244").EntireRow.Hidden = True
                        Rows("245:258").EntireRow.Hidden = True
                        Rows("259:274").EntireRow.Hidden = True
                        Rows("275:288").EntireRow.Hidden = True
                        Rows("289:302").EntireRow.Hidden = True
        Case Is = "4":  Rows("5:18").EntireRow.Hidden = False
                        Rows("19:34").EntireRow.Hidden = False
                        Rows("35:48").EntireRow.Hidden = False
                        Rows("49:64").EntireRow.Hidden = False
                        Rows("65:78").EntireRow.Hidden = True
                        Rows("79:94").EntireRow.Hidden = True
                        Rows("95:108").EntireRow.Hidden = True
                        Rows("109:124").EntireRow.Hidden = True
                        Rows("125:138").EntireRow.Hidden = True
                        Rows("139:154").EntireRow.Hidden = True
                        Rows("155:168").EntireRow.Hidden = True
                        Rows("169:184").EntireRow.Hidden = True
                        Rows("185:198").EntireRow.Hidden = True
                        Rows("199:214").EntireRow.Hidden = True
                        Rows("215:228").EntireRow.Hidden = True
                        Rows("229:244").EntireRow.Hidden = True
                        Rows("245:258").EntireRow.Hidden = True
                        Rows("259:274").EntireRow.Hidden = True
                        Rows("275:288").EntireRow.Hidden = True
                        Rows("289:302").EntireRow.Hidden = True
        Case Is = "5":  Rows("5:18").EntireRow.Hidden = False
                        Rows("19:34").EntireRow.Hidden = False
                        Rows("35:48").EntireRow.Hidden = False
                        Rows("49:64").EntireRow.Hidden = False
                        Rows("65:78").EntireRow.Hidden = False
                        Rows("79:94").EntireRow.Hidden = True
                        Rows("95:108").EntireRow.Hidden = True
                        Rows("109:124").EntireRow.Hidden = True
                        Rows("125:138").EntireRow.Hidden = True
                        Rows("139:154").EntireRow.Hidden = True
                        Rows("155:168").EntireRow.Hidden = True
                        Rows("169:184").EntireRow.Hidden = True
                        Rows("185:198").EntireRow.Hidden = True
                        Rows("199:214").EntireRow.Hidden = True
                        Rows("215:228").EntireRow.Hidden = True
                        Rows("229:244").EntireRow.Hidden = True
                        Rows("245:258").EntireRow.Hidden = True
                        Rows("259:274").EntireRow.Hidden = True
                        Rows("275:288").EntireRow.Hidden = True
                        Rows("289:302").EntireRow.Hidden = True
        Case Is = "6":  Rows("5:18").EntireRow.Hidden = False
                        Rows("19:34").EntireRow.Hidden = False
                        Rows("35:48").EntireRow.Hidden = False
                        Rows("49:64").EntireRow.Hidden = False
                        Rows("65:78").EntireRow.Hidden = False
                        Rows("79:94").EntireRow.Hidden = False
                        Rows("95:108").EntireRow.Hidden = True
                        Rows("109:124").EntireRow.Hidden = True
                        Rows("125:138").EntireRow.Hidden = True
                        Rows("139:154").EntireRow.Hidden = True
                        Rows("155:168").EntireRow.Hidden = True
                        Rows("169:184").EntireRow.Hidden = True
                        Rows("185:198").EntireRow.Hidden = True
                        Rows("199:214").EntireRow.Hidden = True
                        Rows("215:228").EntireRow.Hidden = True
                        Rows("229:244").EntireRow.Hidden = True
                        Rows("245:258").EntireRow.Hidden = True
                        Rows("259:274").EntireRow.Hidden = True
                        Rows("275:288").EntireRow.Hidden = True
                        Rows("289:302").EntireRow.Hidden = True
        Case Is = "7":  Rows("5:18").EntireRow.Hidden = False
                        Rows("19:34").EntireRow.Hidden = False
                        Rows("35:48").EntireRow.Hidden = False
                        Rows("49:64").EntireRow.Hidden = False
                        Rows("65:78").EntireRow.Hidden = False
                        Rows("79:94").EntireRow.Hidden = False
                        Rows("95:108").EntireRow.Hidden = False
                        Rows("109:124").EntireRow.Hidden = True
                        Rows("125:138").EntireRow.Hidden = True
                        Rows("139:154").EntireRow.Hidden = True
                        Rows("155:168").EntireRow.Hidden = True
                        Rows("169:184").EntireRow.Hidden = True
                        Rows("185:198").EntireRow.Hidden = True
                        Rows("199:214").EntireRow.Hidden = True
                        Rows("215:228").EntireRow.Hidden = True
                        Rows("229:244").EntireRow.Hidden = True
                        Rows("245:258").EntireRow.Hidden = True
                        Rows("259:274").EntireRow.Hidden = True
                        Rows("275:288").EntireRow.Hidden = True
                        Rows("289:302").EntireRow.Hidden = True
        Case Is = "8":  Rows("5:18").EntireRow.Hidden = False
                        Rows("19:34").EntireRow.Hidden = False
                        Rows("35:48").EntireRow.Hidden = False
                        Rows("49:64").EntireRow.Hidden = False
                        Rows("65:78").EntireRow.Hidden = False
                        Rows("79:94").EntireRow.Hidden = False
                        Rows("95:108").EntireRow.Hidden = False
                        Rows("109:124").EntireRow.Hidden = False
                        Rows("125:138").EntireRow.Hidden = True
                        Rows("139:154").EntireRow.Hidden = True
                        Rows("155:168").EntireRow.Hidden = True
                        Rows("169:184").EntireRow.Hidden = True
                        Rows("185:198").EntireRow.Hidden = True
                        Rows("199:214").EntireRow.Hidden = True
                        Rows("215:228").EntireRow.Hidden = True
                        Rows("229:244").EntireRow.Hidden = True
                        Rows("245:258").EntireRow.Hidden = True
                        Rows("259:274").EntireRow.Hidden = True
                        Rows("275:288").EntireRow.Hidden = True
                        Rows("289:302").EntireRow.Hidden = True
        Case Is = "9":  Rows("5:18").EntireRow.Hidden = False
                        Rows("19:34").EntireRow.Hidden = False
                        Rows("35:48").EntireRow.Hidden = False
                        Rows("49:64").EntireRow.Hidden = False
                        Rows("65:78").EntireRow.Hidden = False
                        Rows("79:94").EntireRow.Hidden = False
                        Rows("95:108").EntireRow.Hidden = False
                        Rows("109:124").EntireRow.Hidden = False
                        Rows("125:138").EntireRow.Hidden = False
                        Rows("139:154").EntireRow.Hidden = True
                        Rows("155:168").EntireRow.Hidden = True
                        Rows("169:184").EntireRow.Hidden = True
                        Rows("185:198").EntireRow.Hidden = True
                        Rows("199:214").EntireRow.Hidden = True
                        Rows("215:228").EntireRow.Hidden = True
                        Rows("229:244").EntireRow.Hidden = True
                        Rows("245:258").EntireRow.Hidden = True
                        Rows("259:274").EntireRow.Hidden = True
                        Rows("275:288").EntireRow.Hidden = True
                        Rows("289:302").EntireRow.Hidden = True
        Case Is = "10":  Rows("5:18").EntireRow.Hidden = False
                        Rows("19:34").EntireRow.Hidden = False
                        Rows("35:48").EntireRow.Hidden = False
                        Rows("49:64").EntireRow.Hidden = False
                        Rows("65:78").EntireRow.Hidden = False
                        Rows("79:94").EntireRow.Hidden = False
                        Rows("95:108").EntireRow.Hidden = False
                        Rows("109:124").EntireRow.Hidden = False
                        Rows("125:138").EntireRow.Hidden = False
                        Rows("139:154").EntireRow.Hidden = False
                        Rows("155:168").EntireRow.Hidden = True
                        Rows("169:184").EntireRow.Hidden = True
                        Rows("185:198").EntireRow.Hidden = True
                        Rows("199:214").EntireRow.Hidden = True
                        Rows("215:228").EntireRow.Hidden = True
                        Rows("229:244").EntireRow.Hidden = True
                        Rows("245:258").EntireRow.Hidden = True
                        Rows("259:274").EntireRow.Hidden = True
                        Rows("275:288").EntireRow.Hidden = True
                        Rows("289:302").EntireRow.Hidden = True
        Case Is = "11":  Rows("5:18").EntireRow.Hidden = False
                        Rows("19:34").EntireRow.Hidden = False
                        Rows("35:48").EntireRow.Hidden = False
                        Rows("49:64").EntireRow.Hidden = False
                        Rows("65:78").EntireRow.Hidden = False
                        Rows("79:94").EntireRow.Hidden = False
                        Rows("95:108").EntireRow.Hidden = False
                        Rows("109:124").EntireRow.Hidden = False
                        Rows("125:138").EntireRow.Hidden = False
                        Rows("139:154").EntireRow.Hidden = False
                        Rows("155:168").EntireRow.Hidden = False
                        Rows("169:184").EntireRow.Hidden = True
                        Rows("185:198").EntireRow.Hidden = True
                        Rows("199:214").EntireRow.Hidden = True
                        Rows("215:228").EntireRow.Hidden = True
                        Rows("229:244").EntireRow.Hidden = True
                        Rows("245:258").EntireRow.Hidden = True
                        Rows("259:274").EntireRow.Hidden = True
                        Rows("275:288").EntireRow.Hidden = True
                        Rows("289:302").EntireRow.Hidden = True
        Case Is = "12":  Rows("5:18").EntireRow.Hidden = False
                        Rows("19:34").EntireRow.Hidden = False
                        Rows("35:48").EntireRow.Hidden = False
                        Rows("49:64").EntireRow.Hidden = False
                        Rows("65:78").EntireRow.Hidden = False
                        Rows("79:94").EntireRow.Hidden = False
                        Rows("95:108").EntireRow.Hidden = False
                        Rows("109:124").EntireRow.Hidden = False
                        Rows("125:138").EntireRow.Hidden = False
                        Rows("139:154").EntireRow.Hidden = False
                        Rows("155:168").EntireRow.Hidden = False
                        Rows("169:184").EntireRow.Hidden = False
                        Rows("185:198").EntireRow.Hidden = True
                        Rows("199:214").EntireRow.Hidden = True
                        Rows("215:228").EntireRow.Hidden = True
                        Rows("229:244").EntireRow.Hidden = True
                        Rows("245:258").EntireRow.Hidden = True
                        Rows("259:274").EntireRow.Hidden = True
                        Rows("275:288").EntireRow.Hidden = True
                        Rows("289:302").EntireRow.Hidden = True
        Case Is = "13":  Rows("5:18").EntireRow.Hidden = False
                        Rows("19:34").EntireRow.Hidden = False
                        Rows("35:48").EntireRow.Hidden = False
                        Rows("49:64").EntireRow.Hidden = False
                        Rows("65:78").EntireRow.Hidden = False
                        Rows("79:94").EntireRow.Hidden = False
                        Rows("95:108").EntireRow.Hidden = False
                        Rows("109:124").EntireRow.Hidden = False
                        Rows("125:138").EntireRow.Hidden = False
                        Rows("139:154").EntireRow.Hidden = False
                        Rows("155:168").EntireRow.Hidden = False
                        Rows("169:184").EntireRow.Hidden = False
                        Rows("185:198").EntireRow.Hidden = False
                        Rows("199:214").EntireRow.Hidden = True
                        Rows("215:228").EntireRow.Hidden = True
                        Rows("229:244").EntireRow.Hidden = True
                        Rows("245:258").EntireRow.Hidden = True
                        Rows("259:274").EntireRow.Hidden = True
                        Rows("275:288").EntireRow.Hidden = True
                        Rows("289:302").EntireRow.Hidden = True
        Case Is = "14":  Rows("5:18").EntireRow.Hidden = False
                        Rows("19:34").EntireRow.Hidden = False
                        Rows("35:48").EntireRow.Hidden = False
                        Rows("49:64").EntireRow.Hidden = False
                        Rows("65:78").EntireRow.Hidden = False
                        Rows("79:94").EntireRow.Hidden = False
                        Rows("95:108").EntireRow.Hidden = False
                        Rows("109:124").EntireRow.Hidden = False
                        Rows("125:138").EntireRow.Hidden = False
                        Rows("139:154").EntireRow.Hidden = False
                        Rows("155:168").EntireRow.Hidden = False
                        Rows("169:184").EntireRow.Hidden = False
                        Rows("185:198").EntireRow.Hidden = False
                        Rows("199:214").EntireRow.Hidden = False
                        Rows("215:228").EntireRow.Hidden = True
                        Rows("229:244").EntireRow.Hidden = True
                        Rows("245:258").EntireRow.Hidden = True
                        Rows("259:274").EntireRow.Hidden = True
                        Rows("275:288").EntireRow.Hidden = True
                        Rows("289:302").EntireRow.Hidden = True
        Case Is = "15":  Rows("5:18").EntireRow.Hidden = False
                        Rows("19:34").EntireRow.Hidden = False
                        Rows("35:48").EntireRow.Hidden = False
                        Rows("49:64").EntireRow.Hidden = False
                        Rows("65:78").EntireRow.Hidden = False
                        Rows("79:94").EntireRow.Hidden = False
                        Rows("95:108").EntireRow.Hidden = False
                        Rows("109:124").EntireRow.Hidden = False
                        Rows("125:138").EntireRow.Hidden = False
                        Rows("139:154").EntireRow.Hidden = False
                        Rows("155:168").EntireRow.Hidden = False
                        Rows("169:184").EntireRow.Hidden = False
                        Rows("185:198").EntireRow.Hidden = False
                        Rows("199:214").EntireRow.Hidden = False
                        Rows("215:228").EntireRow.Hidden = False
                        Rows("229:244").EntireRow.Hidden = True
                        Rows("245:258").EntireRow.Hidden = True
                        Rows("259:274").EntireRow.Hidden = True
                        Rows("275:288").EntireRow.Hidden = True
                        Rows("289:302").EntireRow.Hidden = True
        Case Is = "16":  Rows("5:18").EntireRow.Hidden = False
                        Rows("19:34").EntireRow.Hidden = False
                        Rows("35:48").EntireRow.Hidden = False
                        Rows("49:64").EntireRow.Hidden = False
                        Rows("65:78").EntireRow.Hidden = False
                        Rows("79:94").EntireRow.Hidden = False
                        Rows("95:108").EntireRow.Hidden = False
                        Rows("109:124").EntireRow.Hidden = False
                        Rows("125:138").EntireRow.Hidden = False
                        Rows("139:154").EntireRow.Hidden = False
                        Rows("155:168").EntireRow.Hidden = False
                        Rows("169:184").EntireRow.Hidden = False
                        Rows("185:198").EntireRow.Hidden = False
                        Rows("199:214").EntireRow.Hidden = False
                        Rows("215:228").EntireRow.Hidden = False
                        Rows("229:244").EntireRow.Hidden = False
                        Rows("245:258").EntireRow.Hidden = True
                        Rows("259:274").EntireRow.Hidden = True
                        Rows("275:288").EntireRow.Hidden = True
                        Rows("289:302").EntireRow.Hidden = True
        Case Is = "17":  Rows("5:18").EntireRow.Hidden = False
                        Rows("19:34").EntireRow.Hidden = False
                        Rows("35:48").EntireRow.Hidden = False
                        Rows("49:64").EntireRow.Hidden = False
                        Rows("65:78").EntireRow.Hidden = False
                        Rows("79:94").EntireRow.Hidden = False
                        Rows("95:108").EntireRow.Hidden = False
                        Rows("109:124").EntireRow.Hidden = False
                        Rows("125:138").EntireRow.Hidden = False
                        Rows("139:154").EntireRow.Hidden = False
                        Rows("155:168").EntireRow.Hidden = False
                        Rows("169:184").EntireRow.Hidden = False
                        Rows("185:198").EntireRow.Hidden = False
                        Rows("199:214").EntireRow.Hidden = False
                        Rows("215:228").EntireRow.Hidden = False
                        Rows("229:244").EntireRow.Hidden = False
                        Rows("245:258").EntireRow.Hidden = False
                        Rows("259:274").EntireRow.Hidden = True
                        Rows("275:288").EntireRow.Hidden = True
                        Rows("289:302").EntireRow.Hidden = True
        Case Is = "18":  Rows("5:18").EntireRow.Hidden = False
                        Rows("19:34").EntireRow.Hidden = False
                        Rows("35:48").EntireRow.Hidden = False
                        Rows("49:64").EntireRow.Hidden = False
                        Rows("65:78").EntireRow.Hidden = False
                        Rows("79:94").EntireRow.Hidden = False
                        Rows("95:108").EntireRow.Hidden = False
                        Rows("109:124").EntireRow.Hidden = False
                        Rows("125:138").EntireRow.Hidden = False
                        Rows("139:154").EntireRow.Hidden = False
                        Rows("155:168").EntireRow.Hidden = False
                        Rows("169:184").EntireRow.Hidden = False
                        Rows("185:198").EntireRow.Hidden = False
                        Rows("199:214").EntireRow.Hidden = False
                        Rows("215:228").EntireRow.Hidden = False
                        Rows("229:244").EntireRow.Hidden = False
                        Rows("245:258").EntireRow.Hidden = False
                        Rows("259:274").EntireRow.Hidden = False
                        Rows("275:288").EntireRow.Hidden = True
                        Rows("289:302").EntireRow.Hidden = True
        Case Is = "19":  Rows("5:18").EntireRow.Hidden = False
                        Rows("19:34").EntireRow.Hidden = False
                        Rows("35:48").EntireRow.Hidden = False
                        Rows("49:64").EntireRow.Hidden = False
                        Rows("65:78").EntireRow.Hidden = False
                        Rows("79:94").EntireRow.Hidden = False
                        Rows("95:108").EntireRow.Hidden = False
                        Rows("109:124").EntireRow.Hidden = False
                        Rows("125:138").EntireRow.Hidden = False
                        Rows("139:154").EntireRow.Hidden = False
                        Rows("155:168").EntireRow.Hidden = False
                        Rows("169:184").EntireRow.Hidden = False
                        Rows("185:198").EntireRow.Hidden = False
                        Rows("199:214").EntireRow.Hidden = False
                        Rows("215:228").EntireRow.Hidden = False
                        Rows("229:244").EntireRow.Hidden = False
                        Rows("245:258").EntireRow.Hidden = False
                        Rows("259:274").EntireRow.Hidden = False
                        Rows("275:288").EntireRow.Hidden = False
                        Rows("289:302").EntireRow.Hidden = True
        Case Is = "20":  Rows("5:18").EntireRow.Hidden = False
                        Rows("19:34").EntireRow.Hidden = False
                        Rows("35:48").EntireRow.Hidden = False
                        Rows("49:64").EntireRow.Hidden = False
                        Rows("65:78").EntireRow.Hidden = False
                        Rows("79:94").EntireRow.Hidden = False
                        Rows("95:108").EntireRow.Hidden = False
                        Rows("109:124").EntireRow.Hidden = False
                        Rows("125:138").EntireRow.Hidden = False
                        Rows("139:154").EntireRow.Hidden = False
                        Rows("155:168").EntireRow.Hidden = False
                        Rows("169:184").EntireRow.Hidden = False
                        Rows("185:198").EntireRow.Hidden = False
                        Rows("199:214").EntireRow.Hidden = False
                        Rows("215:228").EntireRow.Hidden = False
                        Rows("229:244").EntireRow.Hidden = False
                        Rows("245:258").EntireRow.Hidden = False
                        Rows("259:274").EntireRow.Hidden = False
                        Rows("275:288").EntireRow.Hidden = False
                        Rows("289:302").EntireRow.Hidden = False
        End Select
        End If
End Sub
 
Last edited by a moderator:

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
You would probably need to move the code out of the Worksheet_Change event macro to a general purpose macro, which can be called from the worksheet change event on this other sheet that you are talking about. In general (not tested) it would be something like this.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    ActiveSheet.Activate
    If Not Application.Intersect(Range("A4"), Range(Target.Address)) Is Nothing Then
        Dim HideSheet As Worksheet
        Set HideSheet = ThisWorkbook.Worksheets("Sheet1")
        HideRows HideSheet, Target
    End If
End Sub

VBA Code:
Private Sub HideRows(ByVal WS As Worksheet, Target As Range)
    Application.ScreenUpdating = False
    With WS
        .Rows("5:302").EntireRow.Hidden = False       'show all rows

        Select Case Target.Value                      'then hide the ones you want to hide
        Case Is = "0": .Rows("5:302").EntireRow.Hidden = True
        Case Is = "1": .Rows("19:302").EntireRow.Hidden = True
        Case Is = "2": .Rows("35:302").EntireRow.Hidden = True
        Case Is = "3": .Rows("49:302").EntireRow.Hidden = True
        Case Is = "4": .Rows("65:302").EntireRow.Hidden = True
        Case Is = "5": .Rows("79:302").EntireRow.Hidden = True
        Case Is = "6": .Rows("95:302").EntireRow.Hidden = True
        Case Is = "7": .Rows("109:302").EntireRow.Hidden = True
        Case Is = "8": .Rows("125:302").EntireRow.Hidden = True
        Case Is = "9": .Rows("139:302").EntireRow.Hidden = True
        Case Is = "10": .Rows("155:302").EntireRow.Hidden = True
        Case Is = "11": .Rows("169:302").EntireRow.Hidden = True
        Case Is = "12": .Rows("185:302").EntireRow.Hidden = True
        Case Is = "13": .Rows("199:302").EntireRow.Hidden = True
        Case Is = "14": .Rows("215:302").EntireRow.Hidden = True
        Case Is = "15": .Rows("229:302").EntireRow.Hidden = True
        Case Is = "16": .Rows("245:302").EntireRow.Hidden = True
        Case Is = "17": .Rows("259:302").EntireRow.Hidden = True
        Case Is = "18": .Rows("275:302").EntireRow.Hidden = True
        Case Is = "19": .Rows("289:302").EntireRow.Hidden = True
        Case Is = "20"
            '.Rows("5:302").EntireRow.Hidden = False
        End Select
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,098
Messages
6,170,099
Members
452,301
Latest member
QualityAssurance

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top