Macro to hide past months?

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,204
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

I have a calendar or list of dates in sheet Cal row 10 range M10:AYX10

each cell has a date in it from M10 = 01/Jan/2018 on

now what id like to do is hide the Months that have past

So when the workbook opens it takes todays date, looks along Row 10 finds the date and Hides all the column before the first of the current month.

any ideas how to do this?

Thanks

Tony
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Assuming it's on the first sheet, try this in the Workbook_Open() handler:

Code:
Private Sub Workbook_Open()

Const firstDateCell = "M10"

Dim firstDate As Date
Dim lastDate As Date

firstDate = Sheets(1).Range(firstDateCell).Value
lastDate = Application.WorksheetFunction.EoMonth(Date, -1)

If lastDate >= firstDate Then
    Sheets(1).Range(firstDateCell).Resize(1, lastDate - firstDate + 1).EntireColumn.Hidden = True
End If

End Sub

WBD
 
Upvote 0

Forum statistics

Threads
1,216,806
Messages
6,132,803
Members
449,760
Latest member
letonuslepus

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