country101
Board Regular
- Joined
- May 31, 2012
- Messages
- 61
Hi, I have a macro that I would think is pretty simple considering how fast I see it do other tasks. I was wondering if anyone sees anything in this code that would make it do unnecessary steps or run longer than necessary. It's just annoying that it takes a bit to run instead of being almost instant, so I figured I would take the time to see if anyone has any knowledge to impart since most of my macros are copy and paste from ones others post without having the knowledge behind them to know why they are structured a certain way.
The sheet has a set of columns and rows that are frozen to show names and hire dates that always need to be visible. One of these is row 3, which shows the days of the year. This macro is designed to hide columns with formulas in them and then hide any columns outside of the range of date+9 so that, when printed, it will show only days that are applicable and will make it easier to find the dates needed for input.
Thanks for the information.
The sheet has a set of columns and rows that are frozen to show names and hire dates that always need to be visible. One of these is row 3, which shows the days of the year. This macro is designed to hide columns with formulas in them and then hide any columns outside of the range of date+9 so that, when printed, it will show only days that are applicable and will make it easier to find the dates needed for input.
Thanks for the information.
Code:
Sub Hide()
'
' Hide Macro
'
' Keyboard Shortcut: Ctrl+h
'
Columns("D").Select
Selection.EntireColumn.Hidden = True
Columns("NV:NW").Select
Selection.EntireColumn.Hidden = True
Dim DateRng As Range
Dim DateCell As Range
Dim WorkSht As Worksheet
Dim cell As Range
For Each cell In Range("E3:NU3")
If cell.Value < Date Or cell.Value > Date + 9 Then
cell.EntireColumn.Hidden = True
End If
Next
For Each WorkSht In Worksheets
WorkSht.Select
Set DateRng = Range("3:3")
For Each DateCell In DateRng
If DateCell.Value = Date Then DateCell.Select
Next
Next WorkSht
Worksheets(1).Select
End Sub