View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default Hide Columns Based on Condition

I assumed you would not have dates going all the way to column IV. It worked
for me in that case. If you do have dates going all the way to column IV
change the code:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim sh As Worksheet, rng As Range, cell As Range
Dim sMenu As String, rngDate As Range
sMenu = LCase(Me.Name)
Set rngDate = Worksheets(sMenu).Range("B9")
If Target.Address = rngDate.Address Then
For Each sh In Worksheets
If LCase(sh.Name) < sMenu Then
sh.Columns.Hidden = False
' Set rng = sh.Range(sh.Cells(1, 1), sh.Cells(1, "IV").End(xlToLeft))
Set rng = sh.Range("A1:IV1")
For Each cell In rng
If IsDate(cell.Value) Then
If cell.Value rngDate.Value Then
cell.EntireColumn.Hidden = True
End If
End If
Next
End If
Next
End If

End Sub

--
Regards,
Tom Ogilvy