Hide Column in one worksheet based on a drop-down in another worksheet

Paynter3420

New Member
Joined
Jun 7, 2016
Messages
5
Hello all! I have two worksheets. The First one "BS1" and the second "PL2." On the first one, I've created a macro that hides certain columns in BS1 if cell L6 says "Single Year" "Comparative" or "Quarterly Comparative." The code is below for this.



Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.Activate
If Not Application.Intersect(Range("L5"), Range(Target.Address)) Is Nothing Then
Select Case Target.Value
Case Is = "Single Year": Columns("F:G").EntireColumn.Hidden = True
Columns("A:E").EntireColumn.Hidden = False
Case Is = "Comparative": Columns("F:G").EntireColumn.Hidden = False
Columns("A:E").EntireColumn.Hidden = False
Case Is = "Quarterly Comparative": Columns("F:G").EntireColumn.Hidden = False
Columns("A:E").EntireColumn.Hidden = False
End Select
End If
End Sub

Now, I'd like to add another macro or modify this macro so that columns F & G will be hidden on "PL2" if the same selections are made.

Thanks for your help!
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
I apologize, the sentence should read "I've created a macro that hides certain columns in BS1 if cell L5 says...
 
Upvote 0
How about
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Not Application.Intersect(Target, Range("L5")) Is Nothing Then
        Select Case Target.Value
            Case Is = "Single Year"
                Columns("F:G").EntireColumn.Hidden = True
                Sheets("PL2").Range("F:G").EntireColumn.Hidden = True
                Columns("A:E").EntireColumn.Hidden = False
            Case Is = "Comparative"
                Columns("F:G").EntireColumn.Hidden = False
                Sheets("PL2").Range("F:G").EntireColumn.Hidden = False
                Columns("A:E").EntireColumn.Hidden = False
            Case Is = "Quarterly Comparative"
                Columns("F:G").EntireColumn.Hidden = False
                Sheets("PL2").Range("F:G").EntireColumn.Hidden = False
                Columns("A:E").EntireColumn.Hidden = False
        End Select
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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