I have an excel file with 2 sheets, and in sheet1 on cell B5 I have a value that changes automatically according other cell. And my goal is to hide columns Y:AN or AQ:BF on sheet2 if B5 on sheet1 is 3 or 2 respectively. I applied the code below, but doesnt work when I protect sheet2.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(False, False) = "B5" Then
Select Case Target.Value
Case "3"
Columns("Y:AN").EntireColumn.Hidden = True
Case "2"
Columns("AQ:BF").EntireColumn.Hidden = True
Case Else
Union(Columns("Y:AN"), Columns("AQ:BF")).EntireColumn.Hidden = False
End Select
End If
End Sub
UserOnlyInterface:=True
. – BigBenSheet1
(which it must be to respond toSheet1!B5
changing) then your code will hide columns onSheet1
. You'll need to qualify them with the required worksheet reference – chris neilsen