VBA If Target.column as drop down list

MSpears93

New Member
Joined
Oct 12, 2021
Messages
2
Office Version
  1. 2019
Platform
  1. Windows
Hi,
I'm using VBA as a drop down so that when I click on the selection it hides all columns except for the ones I need to see for that criteria.

My problem is that once I have selected one of the options e.g Newcastle, to see the next option e.g. Carlisle, I have to go back to Select College and then select Carlisle, otherwise it shows nothing.

I want to be able to select any college without having to go back to Select College. I hope this makes sense.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 1 And Target.Row = 1 Then
        If Target.Value = "Carlisle" Then
            Range("B:R,AJ:DP").EntireColumn.Hidden = True
        ElseIf Target.Value = "Kidderminster" Then
            Range("B:AI,BA:DP").EntireColumn.Hidden = True
        ElseIf Target.Value = "Lewisham" Then
            Range("B:AZ,BR:DP").EntireColumn.Hidden = True
        ElseIf Target.Value = "West Lancashire" Then
            Range("B:CY").EntireColumn.Hidden = True
         ElseIf Target.Value = "Southwark" Then
            Range("B:CH,CZ:DP").EntireColumn.Hidden = True
        ElseIf Target.Value = "Newcastle" Then
            Range("B:BQ,CI:DP").EntireColumn.Hidden = True
        ElseIf Target.Value = "Select College" Then
            Range("B:DP").EntireColumn.Hidden = False
                        

End If
End If
   

End Sub
 
Last edited by a moderator:

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi & welcome to MrExcel.
How about adding this line as shown
VBA Code:
    If Target.Column = 1 And Target.Row = 1 Then
        Range("B:DP").EntireColumn.Hidden = False
        If Target.Value = "Carlisle" Then
 
Upvote 0
Solution
Hi & welcome to MrExcel.
How about adding this line as shown
VBA Code:
    If Target.Column = 1 And Target.Row = 1 Then
        Range("B:DP").EntireColumn.Hidden = False
        If Target.Value = "Carlisle" Then
That's worked perfectly!! Thank you
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top