Hide all columns that are after this weeks date

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,
Ok so I have a list of dates in column AH16 to CH16 that show every monday of this year in reverse order
(CH16 = 03/01/2022 go to the left with each cell going up 7 days until AH16 = 02/01/23)



What i would like is a macro that can do this,
when i select the page, Find this weeks date (that will be the Monday for the week we are in i.e. 07/02/2022 and hide the columns between AH and that column,

Please help if you can

Thanks

Tony
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
I did something similar once, Here's what I did. In my example A4:A63 contained a list of dates and B1 had the current date. You'll need to modify it to work on weeks rather than a specific date, but this should get you started.

Sub Worksheet_Activate()
Application.ScreenUpdating = False
Application.Calculation = xlManual
'Hide all rows to start
Rows("4:63").Hidden = True
'Display row(s) that match date criteria
For Each A In Range("A4:A63")
If A.Value = Range("B1").Value Then Rows(A.Row).Offset(-2, 0).Resize(3).Hidden = False
Next

Application.Calculation = xlAutomatic
Application.ScreenUpdating = True
End Sub
 
Upvote 0
How about
VBA Code:
Private Sub Worksheet_Activate()
   Dim Rng As Range
   Dim Dt As Date

   Dt = Application.WorkDay_Intl(Date + 1, -1, "0111111")
   Set Rng = Range("AH16:CH16").Find(Dt, , , xlWhole, , xlNext, , , False)
   If Rng Is Nothing Then
      MsgBox "oops"
      Exit Sub
   End If
   Range("AH16:CH16").EntireColumn.Hidden = False
   Range("AH16", Rng.Offset(, -1)).EntireColumn.Hidden = True
End Sub
 
Upvote 0
Solution
Thank you candyman, your idea was very unique,
And fluff thank you
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,951
Messages
6,122,449
Members
449,083
Latest member
Ava19

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