Auto Column Date

ExcelRoy

Well-known Member
Joined
Oct 2, 2006
Messages
2,457
Office Version
  1. 2007
Platform
  1. Windows
Hi everyone,

I have the following code that adjusts the previous week and next 2 weeks unhidden when the workbook is opened
The dates are displayed in Row 3 (In columns from column Q:KV)

What i would like is for the display of weekends (Currently only displays weekdays)


Private Sub Workbook_Open()
Dim i As Long
With Worksheets("Live Service Orders")
.Cells.EntireColumn.Hidden = False
For i = 17 To .Cells(3, Columns.Count).End(xlToLeft).Column
If .Cells(3, i).Value < Date - 14 Or .Cells(3, i) > Date + 42 Then
.Columns(i).Hidden = True
ElseIf Weekday(.Cells(3, i), 2) > 5 Then
.Columns(i).Hidden = True
End If
Next
End With
End Sub

Many thanks for any help
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
57,532
Office Version
  1. 365
Platform
  1. Windows
These are the lines that hide the weekend dates (checking for weekday number greater than 5):
VBA Code:
ElseIf Weekday(.Cells(3, i), 2) > 5 Then
.Columns(i).Hidden = True
Simply remove those lines (or comment them out), and it will stop hiding the weekend days.
 

ExcelRoy

Well-known Member
Joined
Oct 2, 2006
Messages
2,457
Office Version
  1. 2007
Platform
  1. Windows
Hi Joe4,

Could this be changed to only show the previous week, and following 2 weeks (Including weekends) instead of days?

Thanks
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
57,532
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

Could this be changed to only show the previous week, and following 2 weeks (Including weekends) instead of days?
Sure. It is pretty easy, when you see what the code is doing, specifically this line:
Rich (BB code):
If .Cells(3, i).Value < Date - 14 Or .Cells(3, i) > Date + 42 Then
Notice the -14 (subtract 2 weeks) and +42 (add 6 weeks).
Just change those to -7 and +14, respectively, to do what you want.
 

ExcelRoy

Well-known Member
Joined
Oct 2, 2006
Messages
2,457
Office Version
  1. 2007
Platform
  1. Windows
Hi Joe4,

Thanks, is it possible for "complete" weeks to be shown and not, lets say from Wednesday as an example but show fromMonday etc

Thanks
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
57,532
Office Version
  1. 365
Platform
  1. Windows
Thanks, is it possible for "complete" weeks to be shown and not, lets say from Wednesday as an example but show fromMonday etc
That is a bit more complex, and is really a new question (as the original question in this thread was really about including weekends).
It would be best to post that in its own new thread.
 

Watch MrExcel Video

Forum statistics

Threads
1,132,805
Messages
5,655,406
Members
418,198
Latest member
jad1984

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top