how to activate a sheet and specific macro help

mgchurch77

New Member
Joined
Aug 15, 2011
Messages
33
I have the following code embedded with a worksheet that hides a column based on a cell reference.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Sheets("Report Data").Range("H39").Value < 2 Then
Columns("C:E").EntireColumn.Hidden = True
Else
Columns("C:E").EntireColumn.Hidden = False
End If
End Sub


What should this look like if I then want to also hide columns F:H if the value is greater than or equal to 2? So basically, if less than 2 hide C:E but show all else (including F:H), if greater than or equal to 2 hide F:H, then show all else (including C:E).
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Sheets("Report Data").Range("H39").Value < 2 Then
        Columns("C:E").EntireColumn.Hidden = True
        Columns("F:H").EntireColumn.Hidden = False
    Else
        Columns("C:E").EntireColumn.Hidden = False
        Columns("F:H").EntireColumn.Hidden = True
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,729
Members
452,939
Latest member
WCrawford

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