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: Naming Tabs for Weeks.

Naming Tabs for Weeks

Written by Allen Wyatt (last updated February 22, 2020)
This tip applies to Excel 97, 2000, 2002, and 2003


3

When you are starting a new workbook, one common scenario calls for creating a year's worth of worksheets, one for each week of the year. In other words, a workbook could end up containing 52 or 53 worksheets, depending on how many weeks there are in a particular year.

If you have a need to create such a workbook, you know that individually creating and naming all the worksheets can be a real hassle. This is where a macro would come in handy. The following macro will add the appropriate number of worksheets, and then rename all of the worksheets according to week number (01 through 52).

Sub YearWorkbook1()
    Dim iWeek As Integer
    Dim sht As Variant
    Application.ScreenUpdating = False
    Worksheets.Add After:=Worksheets(Worksheets.Count), _
      Count:=(52 - Worksheets.Count)
    iWeek = 1
    For Each sht In Worksheets
        sht.Name = "Week " & Format(iWeek, "00")
        iWeek = iWeek + 1
    Next sht
    Application.ScreenUpdating = True
End Sub

If you instead need a way to create worksheets that show the ending date of each week for a year, then a different macro is needed.

Sub YearWorkbook2()
    Dim iWeek As Integer
    Dim sht As Variant
    Dim sTemp As String
    Dim dSDate As Date

    sTemp = InputBox("Date for the first worksheet:", "End of Week?")
    dSDate = CDate(sTemp)
    
    Application.ScreenUpdating = False
    Worksheets.Add After:=Worksheets(Worksheets.Count), _
      Count:=(52 - Worksheets.Count)
    For Each sht In Worksheets
        sht.Name = Format(dSDate, "dd-mmm-yyyy")
        dSDate = dSDate + 7
    Next sht
    Application.ScreenUpdating = True
End Sub

This version of the macro asks you for a beginning date. It then uses that date to start naming the different worksheets in the workbook. If you enter a value that cannot be translated to a date, then the macro will generate an error.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2018) 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: Naming Tabs for Weeks.

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

Dealing with Oily Skin

Does your skin feel greasy to the touch and are you having problems getting just the right look with your facial makeup? ...

Discover More

Forcing a Macro to Run when a Worksheet is Recalculated

Normally a macro is only calculated when you specifically tell Excel to calculate it. Some macros need to be calculated ...

Discover More

Setting Decimal Tabs in a Table Using the Keyboard

Most people use the mouse to set tab stops in the paragraphs in a table. If you prefer to not use the mouse, then you'll ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (menu)

Freezing Worksheet Tabs

If you have a lot of worksheets in a workbook, you may wonder if you can "freeze" the position of some of those worksheet ...

Discover More

Getting the Name of the Worksheet Into a Cell

Excel allows you to change the names assigned to the worksheets in a workbook. If you want to have those names appear in ...

Discover More

Picking Worksheets Quickly

If your workbook contains a multitude of worksheets, the worksheet tabs at the bottom of the program window start to ...

Discover More
Subscribe

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

View most recent newsletter.

Comments

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 7 + 0?

2021-12-24 08:36:10

Frank Tate

The macros work like a CHAMP! Thank you!


2020-12-18 11:45:49

Chris

I have the same question as Sylvie La. I already have a template that I need to copy 52-53 times and name the tabs as this macro does. How do I go about doing this please.


2020-05-01 14:08:16

Sylvie La

Hello,

YearWorkbook2 Was exactly what i needed! However, since they open blank tabs, is it possible to copy a form for each new tab that it creates?


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.

Newest Tips
Subscribe

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

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.