View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default Hiding/unhiding columns based on user selection

Sub hidecoluumns()

'sample date for testing
selecteddate = DateValue("12/07/07")

For LastColumn = Columns.Count To 10 Step -1
If Not IsEmpty(Cells(1, LastColumn).Value) Then
Exit For
End If
Next LastColumn

For columncount = 10 To LastColumn

If Cells(1, columncount).Value selecteddate Then
Cells(1, columncount).EntireColumn.Hidden = True
Else
Cells(1, columncount).EntireColumn.Hidden = False

End If
Next columncount

End Sub


"Bob" wrote:

I have pairs of columns representing Mgmt. and Non-Mgmt. Hours for each month
of 2007 and 2008, starting in column J. For example, columns P and Q contain
the hours for Mgmt. and Non-Mgmt for April 2007, respectively.

I also have a drop-down list box where a user can select the Last-Month/Year
of data they want to see. The choices displayed in the drop-down list box
come from a 1-column range called Choices_End_Period.

I would like to write a macro that automatically hides the columns of data
beyond the Last-Month/Year that was selected. For example, if a user selects
June 2007, columns V €“ BE would automatically be hidden. However, if a user
changed their mind and selected October 2008, columns V €“ BA would
automatically be unhidden, but columns BB €“ BE would remain hidden. Etc.

Since I am a novice when it comes to writing VBA code, I would greatly
appreciate any help.

Thanks,
Bob