ranjanagarwal
New Member
- Joined
- Jul 12, 2015
- Messages
- 13
The problem I am having with the following code is that I am not able to select the values one after the other. I always have to go back to empty cell value before I can select the other value.
For example; if I select "1st' it displays the required info and hides the columns that are supposed to hidden. If I go next and select '2nd' as value it will hide all the columns instead of just hiding the required ones. However if I select an empty cell value and then select '2nd' then it works fine.
Second issue that I am having is that I am not able to name it anything else such as 'Game 1', 'Game 2' etc Is there some sort of restriction?
Thanks in advance for looking into this.
This code was from an old post on the website and amended it to suit my need.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count = 1 And Target.Address = "$C$3" Then
If LCase(Target.Value) = "1st" Then
Columns("F:U").EntireColumn.Hidden = True
ElseIf LCase(Target.Value) = "2nd" Then
Columns("H:U").EntireColumn.Hidden = True
Columns("D:E").EntireColumn.Hidden = True
ElseIf LCase(Target.Value) = "3rd" Then
Columns("J:U").EntireColumn.Hidden = True
Columns("D:G").EntireColumn.Hidden = True
ElseIf LCase(Target.Value) = "4th" Then
Columns("L:U").EntireColumn.Hidden = True
Columns("D:I").EntireColumn.Hidden = True
ElseIf LCase(Target.Value) = "5th" Then
Columns("N:U").EntireColumn.Hidden = True
Columns("D:K").EntireColumn.Hidden = True
ElseIf LCase(Target.Value) = "6th" Then
Columns("P:U").EntireColumn.Hidden = True
Columns("D:M").EntireColumn.Hidden = True
ElseIf LCase(Target.Value) = "7th" Then
Columns("R:U").EntireColumn.Hidden = True
Columns("D:O").EntireColumn.Hidden = True
ElseIf LCase(Target.Value) = "8th" Then
Columns("T:U").EntireColumn.Hidden = True
Columns("D:Q").EntireColumn.Hidden = True
ElseIf LCase(Target.Value) = "9th" Then
Columns("D:S").EntireColumn.Hidden = True
Else
Columns("D:U").EntireColumn.Hidden = False
End If
End If
End Sub
For example; if I select "1st' it displays the required info and hides the columns that are supposed to hidden. If I go next and select '2nd' as value it will hide all the columns instead of just hiding the required ones. However if I select an empty cell value and then select '2nd' then it works fine.
Second issue that I am having is that I am not able to name it anything else such as 'Game 1', 'Game 2' etc Is there some sort of restriction?
Thanks in advance for looking into this.
This code was from an old post on the website and amended it to suit my need.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count = 1 And Target.Address = "$C$3" Then
If LCase(Target.Value) = "1st" Then
Columns("F:U").EntireColumn.Hidden = True
ElseIf LCase(Target.Value) = "2nd" Then
Columns("H:U").EntireColumn.Hidden = True
Columns("D:E").EntireColumn.Hidden = True
ElseIf LCase(Target.Value) = "3rd" Then
Columns("J:U").EntireColumn.Hidden = True
Columns("D:G").EntireColumn.Hidden = True
ElseIf LCase(Target.Value) = "4th" Then
Columns("L:U").EntireColumn.Hidden = True
Columns("D:I").EntireColumn.Hidden = True
ElseIf LCase(Target.Value) = "5th" Then
Columns("N:U").EntireColumn.Hidden = True
Columns("D:K").EntireColumn.Hidden = True
ElseIf LCase(Target.Value) = "6th" Then
Columns("P:U").EntireColumn.Hidden = True
Columns("D:M").EntireColumn.Hidden = True
ElseIf LCase(Target.Value) = "7th" Then
Columns("R:U").EntireColumn.Hidden = True
Columns("D:O").EntireColumn.Hidden = True
ElseIf LCase(Target.Value) = "8th" Then
Columns("T:U").EntireColumn.Hidden = True
Columns("D:Q").EntireColumn.Hidden = True
ElseIf LCase(Target.Value) = "9th" Then
Columns("D:S").EntireColumn.Hidden = True
Else
Columns("D:U").EntireColumn.Hidden = False
End If
End If
End Sub