Auto Hide Columns based on passed Dates!!!

MarkReddell

Board Regular
Joined
Sep 1, 2011
Messages
210
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
Good Morning 2 ALL!!! I need help with macro to auto hide all columns w/passed dates! Starting in F5 which has the date 1/1/2018, to the end of W/S columns always in row 5. All dates are progressive to the end of W/S Columns! Is this possible??? Thanks for any help!!! :confused: :confused: :confused:
 
How about a call macro when file opens??? That would work to auto hide columns when file opens! Fishboy wrote this for someone else. I've tried to modify, but having issues!Private Sub Workbook_Open()
' Defines variables

Dim Cell As Range, cRange As Range
Dim mDay As Date, sDay As Date
' Workout the Monday and Sunday of the current week
mDay = Date - Weekday(Date, vbMonday) + 1
sDay = Date - Weekday(Date, vbUseSystemDayOfWeek) + 7
' Disables screen updating to reduce flicker
Application.ScreenUpdating = False
' Defines the last column as the last column with a date in row 4
LastCol = Sheets("Master Show Schedule").Cells(4, Columns.Count).End(xlToLeft).Column
' Set the check range as A14 to the last column of row 4
Set cRange = Sheets("Master Show Schedule").Range("F4", Cells(4, LastCol))
' Unhides all columns in the check range
cRange.Columns.Hidden = False
' For each cell in the check range
For Each Cell In cRange
' If the date is before Monday of the current week or after Sunday of the current week then...
If Cell.Value < mDay Then
' Hide the column
Cell.EntireColumn.Hidden = True
ElseIf Cell.Value > sDay Then
Cell.EntireColumn.Hidden = True
End If
' Check next cell in the check range
Next Cell
' Re-enable screen updating
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Re,

If this is what you need ... you can use the Workbook_Open event ... :wink:
 
Upvote 0
Try this:
This script will activate when you open your Workbook:

This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on any sheet tab
Select View Code from the pop-up context menu
In upper left corner of widow double click on ThisWorkbook

Paste the code in the VBA edit window
This script assumes the sheet name you want this script to work on is named Master
Modify name to your needs.

Code:
Private Sub Workbook_Open()
Sheets("Master").Activate
'Modified  9/22/2018  4:44:20 AM  EDT
Dim r As Range
Dim LastColumn As Long
LastColumn = Cells(5, Columns.Count).End(xlToLeft).Column
   For Each r In Cells(5, 6).Resize(, LastColumn - 6)
   If r.Value < Date Then Columns(r.Column).Hidden = True
   Next
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,021
Latest member
pingpong7117

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