How do I auto hide column when a specific cell is equal to 4; Cell P2 will have either a 4 or a 5, when it is equal to 4, I need column "O" to be hidden.
Try this. Adapted from some code by Mr Andrew Poulsom
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> "$P$2" Then Exit Sub
With Worksheets("Sheet1")
.Columns("O").Hidden = Target.Value = 4
End With
End Sub
The code needs to go in the worksheet module
1) Copy the code that you want to use
2) Select the worksheet in which you the code to run
3) Right click on the sheet tab and choose View Code, to open the Visual Basic Editor.
4) Where the cursor is flashing, choose Edit | Paste
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Range("P2").Value = "4" Then
Range("O2").EntireColumn.Hidden = True
Else
If Range("P2").Value <> "4" Then
Range("O2").EntireColumn.Hidden = False
Else
Exit Sub
End If
End If
End Sub
Note: this does have to be put into the worksheet module you want this to run on.
No problem. I can usually help on the small issues. Its the big ones that i sometimes need to defer to some of the other more knowledgeable users on here.
Yes...It's just ugly and in the way when not being used during a regular "4 week" month...I will just manually hide it - I have also used the If Then formula to return blanks when not being used - this helps clean it up a bit.
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.