Hide/Unhide a Column based on a condition

  • Thread starter Thread starter John
  • Start date Start date
J

John

I have not used Macros before in excel so please be gentle with me.

I want to be able to hide a column based on the value of a cell. For
example, IF A1="5A" hide the column headed 'MR' IF A1="7A" unhide the
column headed 'MR'

If a macro is needed, I want it to run when the Value is entered into
A1 without the user having to run the macro manually. I also want to
limit the column range. Ie: I only want to hide/unhide out to column
DA

Also if a macro is needed, how do I insert it etc.

Any help is appreciated

Regards
John
 
Hi John
if you want to hide the column DA you may try the following event
procedure. For more details about event procedures and macros see:
http://www.cpearson.com/excel/events.htm
http://www.mvps.org/dmcritchie/excel/getstarted.htm



Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Me.Range("A1")) Is Nothing Then Exit Sub
On Error GoTo CleanUp
application.enableevents = false
With Target
If .Value "5A" Then
columns("DA").hidden=true
elseif .value="7A" then
columns("DA").hidden=false
End If
End With
CleanUp:
Application.EnableEvents = True
End Sub
 
Back
Top