Hi, very new to VBA, trying to hide rows based on cell value changes and have it update every time a drop down menu is used. Below is what I've done but it doesn't work..
The cells B4 and so on have a formula which its result changes based on said drop down. Not sure if there's more information I could provide.
The cells B4 and so on have a formula which its result changes based on said drop down. Not sure if there's more information I could provide.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ws As Worksheet
Dim hideValue As String
Set ws = ThisWorkbook.Worksheets("Interval Breakdown")
If Target.Address = "$A$2" Then ' Check if A2 changed
' Range CDA
hideValue = ws.Range("B4").Value
If hideValue = "0" Then
ws.Range("A20:A23").Hidden = True
ws.Range("A56:A59").Hidden = True
ws.Range("A92:A95").Hidden = True
ws.Range("A128:A131").Hidden = True
ws.Range("A164:A167").Hidden = True
ws.Range("A200:A203").Hidden = True
ws.Range("A236:A239").Hidden = True
ws.Range("A281:A283").Hidden = True
ws.Range("A305:A308").Hidden = True
ws.Range("A350:A352").Hidden = True
ElseIf hideValue > "0" Then
ws.Range("A20:A23").Hidden = False
ws.Range("A56:A59").Hidden = False
ws.Range("A92:A95").Hidden = False
ws.Range("A128:A131").Hidden = False
ws.Range("A164:A167").Hidden = False
ws.Range("A200:A203").Hidden = False
ws.Range("A236:A239").Hidden = False
ws.Range("A281:A283").Hidden = False
ws.Range("A305:A308").Hidden = False
ws.Range("A350:A352").Hidden = False
End If
' Range MYS
hideValue = ws.Range("B5").Value
If hideValue = "0" Then
ws.Range("A24:A29").Hidden = True
ws.Range("A60:A65").Hidden = True
ws.Range("A96:A101").Hidden = True
ws.Range("A132:A137").Hidden = True
ws.Range("A168:A173").Hidden = True
ws.Range("A204:A209").Hidden = True
ws.Range("A240:A245").Hidden = True
ws.Range("A284:A286").Hidden = True
ws.Range("A309:A312").Hidden = True
ws.Range("A353:A355").Hidden = True
ElseIf hideValue > "0" Then
ws.Range("A24:A29").Hidden = False
ws.Range("A60:A65").Hidden = False
ws.Range("A96:A101").Hidden = False
ws.Range("A132:A137").Hidden = False
ws.Range("A168:A173").Hidden = False
ws.Range("A204:A209").Hidden = False
ws.Range("A240:A245").Hidden = False
ws.Range("A284:A286").Hidden = False
ws.Range("A309:A312").Hidden = False
ws.Range("A353:A355").Hidden = False
End If
' Range POL
hideValue = ws.Range("B6").Value
If hideValue = "0" Then
ws.Range("A30:A33").Hidden = True
ws.Range("A66:A69").Hidden = True
ws.Range("A102:A105").Hidden = True
ws.Range("A138:A141").Hidden = True
ws.Range("A174:A177").Hidden = True
ws.Range("A210:A213").Hidden = True
ws.Range("A246:A249").Hidden = True
ws.Range("A287:A289").Hidden = True
ws.Range("A313:A316").Hidden = True
ws.Range("A356:A358").Hidden = True
ElseIf hideValue > "0" Then
ws.Range("A30:A33").Hidden = False
ws.Range("A66:A69").Hidden = False
ws.Range("A102:A105").Hidden = False
ws.Range("A138:A141").Hidden = False
ws.Range("A174:A177").Hidden = False
ws.Range("A210:A213").Hidden = False
ws.Range("A246:A249").Hidden = False
ws.Range("A287:A289").Hidden = False
ws.Range("A313:A316").Hidden = False
ws.Range("A356:A358").Hidden = False
End If
' Range POR
hideValue = ws.Range("B7").Value
If hideValue = "0" Then
ws.Range("A34:A37").Hidden = True
ws.Range("A70:A73").Hidden = True
ws.Range("A106:A109").Hidden = True
ws.Range("A142:A145").Hidden = True
ws.Range("A178:A181").Hidden = True
ws.Range("A214:A217").Hidden = True
ws.Range("A250:A253").Hidden = True
ws.Range("A290:A292").Hidden = True
ws.Range("A317:A320").Hidden = True
ws.Range("A359:A361").Hidden = True
ElseIf hideValue > "0" Then
ws.Range("A34:A37").Hidden = False
ws.Range("A70:A73").Hidden = False
ws.Range("A106:A109").Hidden = False
ws.Range("A142:A145").Hidden = False
ws.Range("A178:A181").Hidden = False
ws.Range("A214:A217").Hidden = False
ws.Range("A250:A253").Hidden = False
ws.Range("A290:A292").Hidden = False
ws.Range("A317:A320").Hidden = False
ws.Range("A359:A361").Hidden = False
End If
End If
End Sub