Conditional hide column [Solved/Closed]

issa - Jul 21, 2011 at 08:05 AM - Latest reply:  issa
- Jul 21, 2011 at 11:59 PM

I need someone to help me please.

I want a VBA code in excel that will look to a value in specific cell (i.e: A1) in one sheet only and if this cell is equal to "1" for instance to hide column No 5 (which is "E") but this to be automatic, I mean if the value changed in A1 it should automatically hide/Undide that column (E) according the value in A1.

Thank you in advance.
See more 

2 replies

Best answer
venkat1926 1865 Posts Sunday June 14, 2009Registration dateContributorStatus July 30, 2015 Last seen - Jul 21, 2011 at 09:54 PM
Thank you
i am rephrasing it

1. if type 1 in A1 column E should be hidden
2. If I type any other number column E should be visible

in that case
right click sheet tab and click view code
in the window that comes up copy this EVENT CODE

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> "$A$1" Then Exit Sub
If Target = 1 Then
Range("e1").EntireColumn.Hidden = True
Range("e1").EntireColumn.Hidden = False
End If
End Sub

now type some number in A1. if it is 1 colum E will be hidden
if it some other number the column E will not be hidden

if you enter in any cell other than A1 nothing will happen

do some experiments.

Thank you, venkat1926 3

Something to say? Add comment

CCM has helped 1702 users this month

Thank you
Thank you indeed.
It worked as needed.
Thanks again.