View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Automatically hide/unhide columns

This actually just looks at H7 to see if it's a Yes. If it's a yes, then M and
R are hidden. Anything else and M and R are shown.

If that's ok, rightclick on the worksheet tab that should have this behavior.
Select view code and paste this into the code window:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

'one cell at a time!
If Target.Cells.Count 1 Then Exit Sub

If Not (Intersect(Target, Me.Range("H7")) Is Nothing) Then
'in H7
Me.Range("M1,R1").EntireColumn.Hidden _
= CBool(LCase(Target.Value) = LCase("no"))
ElseIf Not (Intersect(Target, Me.Range("H6")) Is Nothing) Then
Me.Range("P:S").EntireColumn.Hidden _
= CBool(LCase(Target.Value) = LCase("total $"))
Me.Range("k:n").EntireColumn.Hidden _
= CBool(LCase(Target.Value) = LCase("$/eq t"))
End If

End Sub

laststraw wrote:

I have a validation box with yes/no options in it in cell H7.
When "no" is selected I would like to hide columns M and R only. When yes
is selected I would like these columns to be displayed.

In the same worksheet I have a validation in cell H6 but would like columns
P:S hidden if "Total $" is selected from the validation list, columns K:N
hidden if "$/eq T" is selected and columns K:S visible if "Total $ & $/eq T"
is selected.

I need the first validation to work in conjunction with the second so that
for example, if total $ is selected and H7 has "yes" selected, only columns
K:N are visible.

I am working with Excel 2003 and my knowledge of VBA is extremely basic,
extending only to pasting code into a module.

I am very grateful for any help you can give me on this one. Thanks!!


--

Dave Peterson