Hide/Unhide a Column based on a condition

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
 
F

Frank Kabel

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top