If true, hide Range("P:U") & Range ("V:AA")

jelle1100

New Member
Joined
Nov 12, 2015
Messages
7
Code:
Private Sub Worksheet_Change(ByVal Target As Range)    If Not Intersect(Range("H2"), Target) Is Nothing Then
       
        If Worksheets("2016!").Range("h2") = "SIS" Then
        Range("P:U").EntireColumn.Hidden = True
        Range("V:AA").EntireColomn.Hidden = False 'this line gives a runtime error 438


        End If


    End If
End Sub

There is a drop-down list in h2 with three options. "SIS" should hide the first range, but show the second range. Than "AGP" should show the first range, but hide the second range and "AA" should show both ranges. Can someone help me with this?
 

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.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)    If Not Intersect(Range("H2"), Target) Is Nothing Then
       
        If Worksheets("2016!").Range("h2") = "SIS" Then
        Range("P:U").EntireColumn.Hidden = True
        Range("V:AA").Entire[B][COLOR="#FF0000"]Colomn[/COLOR][/B].Hidden = False 'this line gives a runtime error 438


        End If


    End If
End Sub
You spelled Column wrong (see red highlighted text).


There is a drop-down list in h2 with three options. "SIS" should hide the first range, but show the second range. Than "AGP" should show the first range, but hide the second range and "AA" should show both ranges. Can someone help me with this?
What is the third option and what should happen for it?
 
Upvote 0
What is the third option and what should happen for it?
Rick, I think these are the 3 options and desired results.

There is a drop-down list in h2 with three options. "SIS" should hide the first range, but show the second range. Than "AGP" should show the first range, but hide the second range and "AA" should show both ranges.
 
Upvote 0
thank you! It works fine now. Also with the other lines added
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Range("H2"), Target) Is Nothing Then


        If Worksheets("2016!").Range("h2") = "SIS" Then
        Range("P:U").EntireColumn.Hidden = False
        Range("V:AA").EntireColumn.Hidden = True
        Else


            If Worksheets("2016!").Range("h2") = "AGP" Then
            Range("P:U").EntireColumn.Hidden = True
            Range("V:AA").EntireColumn.Hidden = False
            Else


                If Worksheets("2016!").Range("h2") = "AA" Then
                Range("P:U").EntireColumn.Hidden = False
                Range("V:AA").EntireColumn.Hidden = False
                Else


                    If Worksheets("2016!").Range("h2") = "AGP & SIS" Then
                    Range("P:U").EntireColumn.Hidden = False
                    Range("V:AA").EntireColumn.Hidden = False








                    End If
                End If
            End If
        End If
    End If


    End Sub
 
Upvote 0
Assuming the worksheet whose Change event you are monitoring is 2016!, then this code should work...
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Address(0, 0) = "H2" Then
    Range("P:U,V:AA").EntireColumn.Hidden = True
    If Target <> "AA" Then
      Columns("P:U").Hidden = Not Target = "SIS"
      Columns("V:AA").Hidden = Not Target = "AG"
    End If
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,119
Messages
6,128,946
Members
449,480
Latest member
yesitisasport

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