Hello, am new to VBA and am struggling with a code that isn't running as expected.
This is what I want to achieve.
a) If one selects "Yes" in cell C8 of worksheet "summary", then rows (8:13) in worksheets "financials" & "ROI" are hidden
b) If one selects "No" in cell C8 of worksheet "summary", then rows (8:13) in worksheets "financials" & "ROI" are unhidden
c) If one selects "Yes" in cell C9 of worksheet "summary", then rows (30:50) in worksheets "financials" & "ROI" are hidden
d) If one selects "No" in cell C9 of worksheet "summary", then rows (30:50) in worksheets "financials" & "ROI" are unhidden
This is the code i wrote....not sure why its not working.....someone please help
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Target.Address <> "$C$9" Then Exit Sub
With Sheets("Financials").Rows("30:50").EntireRow
If Target.Value = "Yes" Then
.Hidden = True
Else
.Hidden = False
End If
End With
If Target.Address <> "$C$9" Then Exit Sub
With Sheets("ROI").Rows("28:45").EntireRow
If Target.Value = "No" Then
.Hidden = True
Else
.Hidden = False
End If
End With
If Target.Address <> "$C$8" Then Exit Sub
With Sheets("Financials").Rows("8:13").EntireRow
If Target.Value = "Yes" Then
.Hidden = True
Else
.Hidden = False
End If
End With
If Target.Address <> "$C$8" Then Exit Sub
With Sheets("ROI").Rows("8:13").EntireRow
If Target.Value = "No" Then
.Hidden = True
Else
.Hidden = False
End If
End With
End Sub
This is what I want to achieve.
a) If one selects "Yes" in cell C8 of worksheet "summary", then rows (8:13) in worksheets "financials" & "ROI" are hidden
b) If one selects "No" in cell C8 of worksheet "summary", then rows (8:13) in worksheets "financials" & "ROI" are unhidden
c) If one selects "Yes" in cell C9 of worksheet "summary", then rows (30:50) in worksheets "financials" & "ROI" are hidden
d) If one selects "No" in cell C9 of worksheet "summary", then rows (30:50) in worksheets "financials" & "ROI" are unhidden
This is the code i wrote....not sure why its not working.....someone please help
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Target.Address <> "$C$9" Then Exit Sub
With Sheets("Financials").Rows("30:50").EntireRow
If Target.Value = "Yes" Then
.Hidden = True
Else
.Hidden = False
End If
End With
If Target.Address <> "$C$9" Then Exit Sub
With Sheets("ROI").Rows("28:45").EntireRow
If Target.Value = "No" Then
.Hidden = True
Else
.Hidden = False
End If
End With
If Target.Address <> "$C$8" Then Exit Sub
With Sheets("Financials").Rows("8:13").EntireRow
If Target.Value = "Yes" Then
.Hidden = True
Else
.Hidden = False
End If
End With
If Target.Address <> "$C$8" Then Exit Sub
With Sheets("ROI").Rows("8:13").EntireRow
If Target.Value = "No" Then
.Hidden = True
Else
.Hidden = False
End If
End With
End Sub