Hi,
I have a worksheet which has 2 fields (cells). When these values change i would like my VB code to hide a range of cells.
The 1st code works fine:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$E$15" Then
If Target.Value = "All Sites" Then
Range(Rows(26), Rows(40)).EntireRow.Hidden = True
Range(Rows(26), Rows(40)).EntireRow.Hidden = False
End If
If Target.Value = "Inhouse" Then
Range(Rows(26), Rows(40)).EntireRow.Hidden = True
Range(Rows(26), Rows(31)).EntireRow.Hidden = False
End If
If Target.Value = "Outsource" Then
Range(Rows(26), Rows(40)).EntireRow.Hidden = True
Range(Rows(32), Rows(40)).EntireRow.Hidden = False
End If
End If
End Sub
However when i add in the 2nd range it fails and not sure why?
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$E$15" Then
If Target.Value = "All Sites" Then
Range(Rows(26), Rows(40)).EntireRow.Hidden = True
Range(Rows(26), Rows(40)).EntireRow.Hidden = False
End If
If Target.Value = "Inhouse" Then
Range(Rows(26), Rows(40)).EntireRow.Hidden = True
Range(Rows(26), Rows(31)).EntireRow.Hidden = False
End If
If Target.Value = "Outsource" Then
Range(Rows(26), Rows(40)).EntireRow.Hidden = True
Range(Rows(32), Rows(40)).EntireRow.Hidden = False
End If
End If
End Sub
Private Sub WorksheetChange2(ByVal Target As Range)
If Target.Address = "$E$13" Then
If Target.Value = "Consumer" Then
Range(Rows(45), Rows(99)).EntireRow.Hidden = True
Range(Rows(45), Rows(58)).EntireRow.Hidden = False
End If
If Target.Value = "Campaigns" Then
Range(Rows(45), Rows(99)).EntireRow.Hidden = True
Range(Rows(62), Rows(73)).EntireRow.Hidden = False
End If
If Target.Value = "B2B" Then
Range(Rows(45), Rows(99)).EntireRow.Hidden = True
Range(Rows(76), Rows(99)).EntireRow.Hidden = False
End If
End If
End Sub
Bookmarks