Hi,
Is there a way i can shorten the code?
I'm trying to hide multiple columns according to the value i selected from the drop-list.
A few of my value have the same columns requirement to be hidden.
'The code works so far so good (dot line and above) when i select from the drop-down list as it hide the columns accordingly
'but it stop working without error given when i try to inculde other value for different columns
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$4" Then
Dim the_selection As String
the_selection = Sheet3.Range("B4")
If the_selection = "Football" Then
Sheet3.Range("Z:Z,AA:AA,AB:AB,AC:AC,AD:AD").EntireColumn.Hidden = True
Else
If the_selection = "Basketball" Then
Sheet3.Range("Z:Z,AA:AA,AB:AB,AC:AC,AD:AD").EntireColumn.Hidden = True
Else
If the_selection = "Baseball" Then
Sheet3.Range("Z:Z,AA:AA,AB:AB,AC:AC,AD:AD").EntireColumn.Hidden = True
Else
Sheet3.Range("Z:Z,AA:AA,AB:AB,AC:AC,AD:AD").EntireColumn.Hidden = False
----------------------------------------------------------------------------
Else
If the_selection = "F1" Then
Sheet3.Range("J:J,L:L,M:M,R:R,S:S,T:T,U:U,V:V").EntireColumn.Hidden = True
Else
If the_selection = "Daytona" Then
Sheet3.Range("J:J,L:L,M:M,R:R,S:S,T:T,U:U,V:V").EntireColumn.Hidden = True
Else
Sheet3.Range("J:J,L:L,M:M,R:R,S:S,T:T,U:U,V:V").EntireColumn.Hidden = False
Is there a way i can shorten the code?
I'm trying to hide multiple columns according to the value i selected from the drop-list.
A few of my value have the same columns requirement to be hidden.
'The code works so far so good (dot line and above) when i select from the drop-down list as it hide the columns accordingly
'but it stop working without error given when i try to inculde other value for different columns
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$4" Then
Dim the_selection As String
the_selection = Sheet3.Range("B4")
If the_selection = "Football" Then
Sheet3.Range("Z:Z,AA:AA,AB:AB,AC:AC,AD:AD").EntireColumn.Hidden = True
Else
If the_selection = "Basketball" Then
Sheet3.Range("Z:Z,AA:AA,AB:AB,AC:AC,AD:AD").EntireColumn.Hidden = True
Else
If the_selection = "Baseball" Then
Sheet3.Range("Z:Z,AA:AA,AB:AB,AC:AC,AD:AD").EntireColumn.Hidden = True
Else
Sheet3.Range("Z:Z,AA:AA,AB:AB,AC:AC,AD:AD").EntireColumn.Hidden = False
----------------------------------------------------------------------------
Else
If the_selection = "F1" Then
Sheet3.Range("J:J,L:L,M:M,R:R,S:S,T:T,U:U,V:V").EntireColumn.Hidden = True
Else
If the_selection = "Daytona" Then
Sheet3.Range("J:J,L:L,M:M,R:R,S:S,T:T,U:U,V:V").EntireColumn.Hidden = True
Else
Sheet3.Range("J:J,L:L,M:M,R:R,S:S,T:T,U:U,V:V").EntireColumn.Hidden = False