Auto Column Date

ExcelRoy

Well-known Member
Joined
Oct 2, 2006
Messages
2,540
Office Version
  1. 365
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

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
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.
 
Upvote 0
Hi Joe4,

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

Thanks
 
Upvote 0
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.
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,749
Members
448,989
Latest member
mariah3

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
Back
Top