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

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

daverunt

Well-known Member
Joined
Jul 9, 2009
Messages
1,893
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,893
Office Version
  1. 2013
Platform
  1. Windows
You're welcome.
Thanks for getting back.
 

Watch MrExcel Video

Forum statistics

Threads
1,130,303
Messages
5,641,426
Members
417,209
Latest member
Agbarker

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