J
JAW
My VBA code hides certain rows in my spreadsheet - however I have created two
different ones - relying on two different Targets. It will run, but only
pays attention to the last Target I have commanded. What have I done
wrong? Please help as I am an absolute beginner at VBA. Please see code
attached:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Range("G25"), Target) Is Nothing Then
Range("A28:A32").EntireRow.Hidden = True
If Target.Value = "Yes" Then
Range("A28:A32").EntireRow.Hidden = True
Range("A33:A999").EntireRow.Hidden = False
Else
If Target.Value = "" Then
Range("A28:A32").EntireRow.Hidden = True
Range("A33:A999").EntireRow.Hidden = False
Else
Range("A28:A32").EntireRow.Hidden = False
Range("A33:A999").EntireRow.Hidden = True
End If
End If
End If
If Not Application.Intersect(Range("E22"), Target) Is Nothing Then
Range("A53:A59").EntireRow.Hidden = True
If Target.Value = "No" Then
Range("A53:A59").EntireRow.Hidden = True
Else
Range("A53:A59").EntireRow.Hidden = False
End If
End If
End Sub
different ones - relying on two different Targets. It will run, but only
pays attention to the last Target I have commanded. What have I done
wrong? Please help as I am an absolute beginner at VBA. Please see code
attached:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Range("G25"), Target) Is Nothing Then
Range("A28:A32").EntireRow.Hidden = True
If Target.Value = "Yes" Then
Range("A28:A32").EntireRow.Hidden = True
Range("A33:A999").EntireRow.Hidden = False
Else
If Target.Value = "" Then
Range("A28:A32").EntireRow.Hidden = True
Range("A33:A999").EntireRow.Hidden = False
Else
Range("A28:A32").EntireRow.Hidden = False
Range("A33:A999").EntireRow.Hidden = True
End If
End If
End If
If Not Application.Intersect(Range("E22"), Target) Is Nothing Then
Range("A53:A59").EntireRow.Hidden = True
If Target.Value = "No" Then
Range("A53:A59").EntireRow.Hidden = True
Else
Range("A53:A59").EntireRow.Hidden = False
End If
End If
End Sub