Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
dd dd is offline
external usenet poster
 
Posts: 95
Default Worksheet Change: Display/hide columns depending on date

I currently use a userform to display specific columns of data. I would like
to do this automatically depending on the present date.

I figure I may be able to use the worksheet change event to automatically
display and hide specific columns depending on the date. I would also like
to retain the userform to change between them if needed.

My change criteria is as follows:

If the date is less than the fourth of the month, but greater than 25th of
the previous month I want to hide columns J:U using something such as...
(from my current userform)...

Application.Calculation = xlManual
ActiveSheet.Unprotect
Cells.Select
Range("A:Z").Activate
Selection.EntireColumn.Hidden = False
ActiveWindow.SmallScroll ToRight:=4
Columns("J:U").Select
Selection.EntireColumn.Hidden = True
ActiveWindow.ScrollColumn = 1
Range("B10").Select
Application.Calculation = xlCalculationAutomatic

If the date is less that the 11, but greater or equal to the fourth of the
month...

Application.Calculation = xlCalculationManual
ActiveSheet.Unprotect
Cells.Select
Range("A:Z").Activate
Selection.EntireColumn.Hidden = False
Columns("G:I").Select
Selection.EntireColumn.Hidden = True
Columns("M:U").Select
Selection.EntireColumn.Hidden = True
ActiveWindow.ScrollColumn = 1
Range("B10").Select
Application.Calculation = xlCalculationAutomatic

If the date is less than 18th, but greater or equal to the 11th...

Application.Calculation = xlCalculationManual

ActiveSheet.Unprotect
Cells.Select
Range("A:Z").Activate
Selection.EntireColumn.Hidden = False
Columns("G:L").Select
Selection.EntireColumn.Hidden = True
Columns("P:U").Select
Selection.EntireColumn.Hidden = True
ActiveWindow.ScrollColumn = 1
Range("B10").Select
Application.Calculation = xlCalculationAutomatic

And finally, if the date is less than 25th, but greater or equal to the 18th

Application.Calculation = xlCalculationManual
ActiveSheet.Unprotect
Cells.Select
Range("A:Z").Activate
Selection.EntireColumn.Hidden = False
Columns("G:R").Select
Selection.EntireColumn.Hidden = True
ActiveWindow.ScrollColumn = 1
Range("B10").Select
UserForm1.Hide
Application.Calculation = xlCalculationAutomatic

Kind Regards
Dylan Dawson


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Worksheet Change: Display/hide columns depending on date

I think it is better to be in a workbook open fuinction than a worksheet
change. I cleaaned up the code by using a select case statement. Try this

Private Sub Workbook_Open()

Application.Calculation = xlManual
ActiveSheet.Unprotect

Columns("G:I").Select
Selection.EntireColumn.Hidden = True

Select Case Day(Now())

Case 1 To 3, 26 To 31
Columns("A:Z").Hidden = False
ActiveWindow.SmallScroll ToRight:=4
Columns("J:U").EntireColumn.Hidden = True

Case 4 To 10
Columns("G:I").Hidden = True
Columns("M:U").Hidden = True

Case 11 To 17

Columns("G:L").Hidden = True
Columns("P:U").Hidden = True

Case 18 To 25
Columns("G:R").Hidden = True
End Select

ActiveWindow.ScrollColumn = 1
Range("B10").Select
Application.Calculation = xlCalculationAutomatic

End Sub


"dd" wrote:

I currently use a userform to display specific columns of data. I would like
to do this automatically depending on the present date.

I figure I may be able to use the worksheet change event to automatically
display and hide specific columns depending on the date. I would also like
to retain the userform to change between them if needed.

My change criteria is as follows:

If the date is less than the fourth of the month, but greater than 25th of
the previous month I want to hide columns J:U using something such as...
(from my current userform)...

Application.Calculation = xlManual
ActiveSheet.Unprotect
Cells.Select
Range("A:Z").Activate
Selection.EntireColumn.Hidden = False
ActiveWindow.SmallScroll ToRight:=4
Columns("J:U").Select
Selection.EntireColumn.Hidden = True
ActiveWindow.ScrollColumn = 1
Range("B10").Select
Application.Calculation = xlCalculationAutomatic

If the date is less that the 11, but greater or equal to the fourth of the
month...

Application.Calculation = xlCalculationManual
ActiveSheet.Unprotect
Cells.Select
Range("A:Z").Activate
Selection.EntireColumn.Hidden = False
Columns("G:I").Select
Selection.EntireColumn.Hidden = True
Columns("M:U").Select
Selection.EntireColumn.Hidden = True
ActiveWindow.ScrollColumn = 1
Range("B10").Select
Application.Calculation = xlCalculationAutomatic

If the date is less than 18th, but greater or equal to the 11th...

Application.Calculation = xlCalculationManual

ActiveSheet.Unprotect
Cells.Select
Range("A:Z").Activate
Selection.EntireColumn.Hidden = False
Columns("G:L").Select
Selection.EntireColumn.Hidden = True
Columns("P:U").Select
Selection.EntireColumn.Hidden = True
ActiveWindow.ScrollColumn = 1
Range("B10").Select
Application.Calculation = xlCalculationAutomatic

And finally, if the date is less than 25th, but greater or equal to the 18th

Application.Calculation = xlCalculationManual
ActiveSheet.Unprotect
Cells.Select
Range("A:Z").Activate
Selection.EntireColumn.Hidden = False
Columns("G:R").Select
Selection.EntireColumn.Hidden = True
ActiveWindow.ScrollColumn = 1
Range("B10").Select
UserForm1.Hide
Application.Calculation = xlCalculationAutomatic

Kind Regards
Dylan Dawson



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Worksheet Change: Display/hide columns depending on date

I made a small mistake with copying your code. Here is the corrected version.

Private Sub Workbook_Open()

Application.Calculation = xlManual
ActiveSheet.Unprotect

Columns("A:Z").Hidden = False

Select Case Day(Now())

Case 1 To 3, 26 To 31

ActiveWindow.SmallScroll ToRight:=4
Columns("J:U").EntireColumn.Hidden = True

Case 4 To 10
Columns("G:I").Hidden = True
Columns("M:U").Hidden = True

Case 11 To 17

Columns("G:L").Hidden = True
Columns("P:U").Hidden = True
Case 18 To 25
Columns("G:R").Hidden = True
End Select

ActiveWindow.ScrollColumn = 1
Range("B10").Select
Application.Calculation = xlCalculationAutomatic

End Sub

"dd" wrote:

I currently use a userform to display specific columns of data. I would like
to do this automatically depending on the present date.

I figure I may be able to use the worksheet change event to automatically
display and hide specific columns depending on the date. I would also like
to retain the userform to change between them if needed.

My change criteria is as follows:

If the date is less than the fourth of the month, but greater than 25th of
the previous month I want to hide columns J:U using something such as...
(from my current userform)...

Application.Calculation = xlManual
ActiveSheet.Unprotect
Cells.Select
Range("A:Z").Activate
Selection.EntireColumn.Hidden = False
ActiveWindow.SmallScroll ToRight:=4
Columns("J:U").Select
Selection.EntireColumn.Hidden = True
ActiveWindow.ScrollColumn = 1
Range("B10").Select
Application.Calculation = xlCalculationAutomatic

If the date is less that the 11, but greater or equal to the fourth of the
month...

Application.Calculation = xlCalculationManual
ActiveSheet.Unprotect
Cells.Select
Range("A:Z").Activate
Selection.EntireColumn.Hidden = False
Columns("G:I").Select
Selection.EntireColumn.Hidden = True
Columns("M:U").Select
Selection.EntireColumn.Hidden = True
ActiveWindow.ScrollColumn = 1
Range("B10").Select
Application.Calculation = xlCalculationAutomatic

If the date is less than 18th, but greater or equal to the 11th...

Application.Calculation = xlCalculationManual

ActiveSheet.Unprotect
Cells.Select
Range("A:Z").Activate
Selection.EntireColumn.Hidden = False
Columns("G:L").Select
Selection.EntireColumn.Hidden = True
Columns("P:U").Select
Selection.EntireColumn.Hidden = True
ActiveWindow.ScrollColumn = 1
Range("B10").Select
Application.Calculation = xlCalculationAutomatic

And finally, if the date is less than 25th, but greater or equal to the 18th

Application.Calculation = xlCalculationManual
ActiveSheet.Unprotect
Cells.Select
Range("A:Z").Activate
Selection.EntireColumn.Hidden = False
Columns("G:R").Select
Selection.EntireColumn.Hidden = True
ActiveWindow.ScrollColumn = 1
Range("B10").Select
UserForm1.Hide
Application.Calculation = xlCalculationAutomatic

Kind Regards
Dylan Dawson



  #4   Report Post  
Posted to microsoft.public.excel.programming
dd dd is offline
external usenet poster
 
Posts: 95
Default Worksheet Change: Display/hide columns depending on date

Joel,

Thank you very much for providing a solution to my problem.

Kind Regards
Dylan Dawson


"Joel" wrote in message
...
I made a small mistake with copying your code. Here is the corrected
version.

Private Sub Workbook_Open()

Application.Calculation = xlManual
ActiveSheet.Unprotect

Columns("A:Z").Hidden = False

Select Case Day(Now())

Case 1 To 3, 26 To 31

ActiveWindow.SmallScroll ToRight:=4
Columns("J:U").EntireColumn.Hidden = True

Case 4 To 10
Columns("G:I").Hidden = True
Columns("M:U").Hidden = True

Case 11 To 17

Columns("G:L").Hidden = True
Columns("P:U").Hidden = True
Case 18 To 25
Columns("G:R").Hidden = True
End Select

ActiveWindow.ScrollColumn = 1
Range("B10").Select
Application.Calculation = xlCalculationAutomatic

End Sub

"dd" wrote:

I currently use a userform to display specific columns of data. I would
like
to do this automatically depending on the present date.

I figure I may be able to use the worksheet change event to automatically
display and hide specific columns depending on the date. I would also like
to retain the userform to change between them if needed.

My change criteria is as follows:

If the date is less than the fourth of the month, but greater than 25th of
the previous month I want to hide columns J:U using something such as...
(from my current userform)...

Application.Calculation = xlManual
ActiveSheet.Unprotect
Cells.Select
Range("A:Z").Activate
Selection.EntireColumn.Hidden = False
ActiveWindow.SmallScroll ToRight:=4
Columns("J:U").Select
Selection.EntireColumn.Hidden = True
ActiveWindow.ScrollColumn = 1
Range("B10").Select
Application.Calculation = xlCalculationAutomatic

If the date is less that the 11, but greater or equal to the fourth of the
month...

Application.Calculation = xlCalculationManual
ActiveSheet.Unprotect
Cells.Select
Range("A:Z").Activate
Selection.EntireColumn.Hidden = False
Columns("G:I").Select
Selection.EntireColumn.Hidden = True
Columns("M:U").Select
Selection.EntireColumn.Hidden = True
ActiveWindow.ScrollColumn = 1
Range("B10").Select
Application.Calculation = xlCalculationAutomatic

If the date is less than 18th, but greater or equal to the 11th...

Application.Calculation = xlCalculationManual

ActiveSheet.Unprotect
Cells.Select
Range("A:Z").Activate
Selection.EntireColumn.Hidden = False
Columns("G:L").Select
Selection.EntireColumn.Hidden = True
Columns("P:U").Select
Selection.EntireColumn.Hidden = True
ActiveWindow.ScrollColumn = 1
Range("B10").Select
Application.Calculation = xlCalculationAutomatic

And finally, if the date is less than 25th, but greater or equal to the
18th

Application.Calculation = xlCalculationManual
ActiveSheet.Unprotect
Cells.Select
Range("A:Z").Activate
Selection.EntireColumn.Hidden = False
Columns("G:R").Select
Selection.EntireColumn.Hidden = True
ActiveWindow.ScrollColumn = 1
Range("B10").Select
UserForm1.Hide
Application.Calculation = xlCalculationAutomatic

Kind Regards
Dylan Dawson





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Worksheet Change: Display/hide columns depending on date

If yhou put the code in a workbook open function then you shouldn't use
activesheet. You need to pick a sheet name.

"dd" wrote:

Joel,

Thank you very much for providing a solution to my problem.

Kind Regards
Dylan Dawson


"Joel" wrote in message
...
I made a small mistake with copying your code. Here is the corrected
version.

Private Sub Workbook_Open()

Application.Calculation = xlManual
ActiveSheet.Unprotect

Columns("A:Z").Hidden = False

Select Case Day(Now())

Case 1 To 3, 26 To 31

ActiveWindow.SmallScroll ToRight:=4
Columns("J:U").EntireColumn.Hidden = True

Case 4 To 10
Columns("G:I").Hidden = True
Columns("M:U").Hidden = True

Case 11 To 17

Columns("G:L").Hidden = True
Columns("P:U").Hidden = True
Case 18 To 25
Columns("G:R").Hidden = True
End Select

ActiveWindow.ScrollColumn = 1
Range("B10").Select
Application.Calculation = xlCalculationAutomatic

End Sub

"dd" wrote:

I currently use a userform to display specific columns of data. I would
like
to do this automatically depending on the present date.

I figure I may be able to use the worksheet change event to automatically
display and hide specific columns depending on the date. I would also like
to retain the userform to change between them if needed.

My change criteria is as follows:

If the date is less than the fourth of the month, but greater than 25th of
the previous month I want to hide columns J:U using something such as...
(from my current userform)...

Application.Calculation = xlManual
ActiveSheet.Unprotect
Cells.Select
Range("A:Z").Activate
Selection.EntireColumn.Hidden = False
ActiveWindow.SmallScroll ToRight:=4
Columns("J:U").Select
Selection.EntireColumn.Hidden = True
ActiveWindow.ScrollColumn = 1
Range("B10").Select
Application.Calculation = xlCalculationAutomatic

If the date is less that the 11, but greater or equal to the fourth of the
month...

Application.Calculation = xlCalculationManual
ActiveSheet.Unprotect
Cells.Select
Range("A:Z").Activate
Selection.EntireColumn.Hidden = False
Columns("G:I").Select
Selection.EntireColumn.Hidden = True
Columns("M:U").Select
Selection.EntireColumn.Hidden = True
ActiveWindow.ScrollColumn = 1
Range("B10").Select
Application.Calculation = xlCalculationAutomatic

If the date is less than 18th, but greater or equal to the 11th...

Application.Calculation = xlCalculationManual

ActiveSheet.Unprotect
Cells.Select
Range("A:Z").Activate
Selection.EntireColumn.Hidden = False
Columns("G:L").Select
Selection.EntireColumn.Hidden = True
Columns("P:U").Select
Selection.EntireColumn.Hidden = True
ActiveWindow.ScrollColumn = 1
Range("B10").Select
Application.Calculation = xlCalculationAutomatic

And finally, if the date is less than 25th, but greater or equal to the
18th

Application.Calculation = xlCalculationManual
ActiveSheet.Unprotect
Cells.Select
Range("A:Z").Activate
Selection.EntireColumn.Hidden = False
Columns("G:R").Select
Selection.EntireColumn.Hidden = True
ActiveWindow.ScrollColumn = 1
Range("B10").Select
UserForm1.Hide
Application.Calculation = xlCalculationAutomatic

Kind Regards
Dylan Dawson






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formula to display text depending upon date entered in a cell Rod from B.C. Government Excel Worksheet Functions 2 May 25th 09 10:03 PM
Change Background cell color depending on date and last value of c theBruceGuy Excel Programming 6 June 5th 07 06:54 PM
hide button depending on date Ed Davis Excel Worksheet Functions 1 May 1st 07 08:46 AM
Hide or display column depending on cell content? Niko Excel Programming 7 March 19th 07 12:25 PM
Change the colour of a row depending on the contents of a date cell [email protected] Excel Programming 4 January 17th 06 10:27 PM


All times are GMT +1. The time now is 08:07 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"