Auto Hide Column less than today when workbook open

Raph85

New Member
Joined
Dec 20, 2015
Messages
26
Hi All,

I have a monthly worksheet and I would like to hide the previous dates column automatically when the workbook is open without pressing any button. Would it be possible and Could you please help me with this if it is.

It's a basic workbook with a monthly dates column from B1 as the first date of the month and I would like the previous date column to auto hide daily as we open the spread sheet, so that it will take us direct to today's date column.

Thanks,

Stheven
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

daverunt

Well-known Member
Joined
Jul 9, 2009
Messages
1,908
Office Version
  1. 2013
Platform
  1. Windows
Hi,

You can use a Workbook open event.
Paste the Code in the 'This Workbook' of the VBA project.

There's a line of code for hiding all dates bar the current if required.
Also assumed it is in "Sheet1" so you need to change all references to that if not.

Also a macro to unhide all of the columns might be need. That is pasted into a normal module.

This should get you started.

Code:
Private Sub Workbook_Open()

lCol = Worksheets("Sheet1").Cells(1, Columns.Count).End(xlToLeft).Column

'Start at B
For i = 2 To lCol

'Use this line if you want to hide all dates up to current
If Cells(1, i).Value < Date Then

'Use this line if you want to hide all dates bar current
'If Not Cells(1, i).Value = Date Then

Cells(1, i).EntireColumn.Hidden = True
End If
Next

 
End Sub

Code:
Sub Unhide_all()

 Worksheets("Sheet1").Cells.EntireColumn.Hidden = False
End Sub
 
Last edited:

daverunt

Well-known Member
Joined
Jul 9, 2009
Messages
1,908
Office Version
  1. 2013
Platform
  1. Windows
You're welcome.
Thanks for getting back.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,066
Messages
5,835,195
Members
430,346
Latest member
Emaus_Sedan

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
Top