View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Otto Moehrbach Otto Moehrbach is offline
external usenet poster
 
Posts: 1,090
Default Drop down bar to hide column according to the content of a cell

WL
This macro should do what you want. I wrote the macro so that you could
add conditions and ranges to hide for those conditions. Also, as written,
this macro will hide the designated columns in the sheet that holds the
drop-down and the drop-down is in cell A2. Note that this macro is a sheet
macro and must be placed in the sheet module of that sheet that holds the
drop-down. To access that module, right-click on the sheet tab, select View
Code, and paste this macro into that module. "X" out of the module to
return to the worksheet. HTH Otto
Private Sub Worksheet_Change(ByVal Target As Range)
Dim RngToHide As Range
If Target.Count 1 Then Exit Sub
If Not Intersect(Target, Range("A2")) Is Nothing Then
Select Case Target.Value
Case 2: Set RngToHide = Columns("G:Z")
Case 5: Set RngToHide = Columns("J:Z")
Case Else: Set RngToHide = Range("A1")
End Select
If RngToHide.Address(0, 0) = "A1" Then Exit Sub
Cells.EntireColumn.Hidden = False
RngToHide.EntireColumn.Hidden = True
End If
End Sub
wrote in message
ups.com...
Hi all,

I need help. How can i write a macro such that
when the user select (e.g. 2 ) from the dropdown for, it hides column
G:Z
when the user select (e.g. 5) from the dropdown form, it hides Column
J:Z

Thank you so much.

Cheers
WL