Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Hiding Columns Not within a Date Range.

# Hiding Columns Not within a Date Range

Written by Allen Wyatt (last updated August 5, 2023)
This tip applies to Excel 97, 2000, 2002, and 2003

Jason has a worksheet that contains several columns, each of which represent a fiscal week for his company. These fiscal weeks begin with column G, with column H being the second fiscal week, column I being the third week, and so forth. Jason would like to create a macro that, when run, would look at today's date, calculate the fiscal week based on that date, and then hide any of the fiscal-week columns that are not within a specified range.

For the purposes of providing an answer, I'm going to assume that the range you want displayed will be equal to the 13 weeks (one quarter) immediately preceding the current fiscal week. With this in mind, there are a couple of things that must be done by the macro. First, it must determine what fiscal week it currently is. Then, it must hide all weeks not in the 13 weeks prior to this current fiscal week and unhide all those that are.

This is all relatively easy to do, with the exception of figuring out which fiscal week it currently is. The method of determining fiscal weeks can vary wildly from company to company. For simplicity's sake, however, I'm going to assume that the determination is fairly straightforward: divide the day of the year by seven and see what we have.

The following macro implements the approach discussed so far.

```Sub HideWeeks()
Dim BeginYear As Date           'start of fiscal year date
Dim FirstWeekCol As Integer     'first fiscal week column
Dim FirstShowWkCol As Integer   'first column to show
Dim CurrWkCol As Integer        'current week column
Dim J As Integer

BeginYear = Cells(1, 1).Value
FirstWeekCol = 7  'fiscal weeks begin with Col 7 (G)

'Calculate Column of the current fiscal week
CurrWkCol = ((Date - BeginYear) \ 7) + FirstWeekCol - 1
'Calculate column of the first week to show
FirstShowWkCol = CurrWkCol - 14
If FirstShowWkCol < FirstWeekCol Then
FirstShowWkCol = FirstWeekCol
End If

Application.ScreenUpdating = False

'Unhide all columns
Columns("G:IV").Hidden = False  'Unhide all week Columns

'Hide week column before the rolling quarter
For J = FirstWeekCol To FirstShowWkCol
Columns(J).Hidden = True
Next J

'Hide week column after current week
For J = CurrWkCol + 1 To 256
Columns(J).Hidden = True
Next intCol

Application.ScreenUpdating = True
End Sub
```

Note that there is one value that must be grabbed from the worksheet in this macro: the last day of the prior year. It is assumed that this is in cell A1, and it is grabbed and placed in the BeginYear variable. This value is used to determine the day of the current year.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3261) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Hiding Columns Not within a Date Range.

##### Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

##### MORE FROM ALLEN

Batch Template Changes

Changing the template associated with a couple of documents is easy, but what if a whole directory needs to be changed? ...

Discover More

Transferring Fonts

Do you want to transfer fonts from one computer system to another? It is relatively easy to do, but there is one ...

Discover More

Saving Changes when Closing

If your macro closes workbooks, you'll want to make sure that it will save any changes you made to the workbook. Here's ...

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

Changing Column Width

When creating a worksheet, you often need to adjust the width of columns so your data looks great. Here's how to quickly ...

Discover More

Centering Across Columns

Have a heading you need centered across a few columns? It's easy to do using the tool described in this tip.

Discover More

Unhiding Columns that are Persistently Hidden

If you were trying to format a worksheet and nothing you did could make the first two columns appear, would you be ...

Discover More
##### Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. Youâ€™ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is eight more than 7?

There are currently no comments for this tip. (Be the first to leave your commentâ€”just use the simple form above!)

##### This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.