Auto Date selections

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 (By the day)
The dates are displayed in Row 3 (In columns from column Q:KV)

is it possible for "complete" weeks to be shown and not, lets say from Wednesday as an example but show from Monday thru to Sunday, before todyas date and from Monday thru Sunday the follwoing 2 weeks


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 - 7 Or .Cells(3, i) > Date + 14 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

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
VBA Code:
Dim i As Long
With Worksheets("Live Service Orders")
    .Cells.EntireColumn.Hidden = False
    'For i = 17 To .Cells(3, Columns.Count).End(xlToLeft).Column
    myToday = Date
    myWeekday = Weekday(myToday, 2)
    For i = 17 To .Cells(3, Columns.Count).End(xlToLeft).Column
        If .Cells(3, i).Value <= myToday - myWeekday Or .Cells(3, i) > myToday + 7 - myWeekday + 14 Then
            .Columns(i).Hidden = True
        End If
    Next
End With
 
Upvote 0
Hi mart37,

Throws a compile error?

Maybe something missing at the start?

Thanks for helping though!
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,536
Members
449,037
Latest member
tmmotairi

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