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

by Allen Wyatt
(last updated December 29, 2012)

6

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

Zooming with the Keyboard

Want to zoom in and out without the need to use the mouse? You can create your own handy macros that do the zooming for you.

Discover More

Tracing Errors

Sometimes it can be confusing to figure out the source of an error that is displayed in your worksheet. Excel provides a ...

Discover More

Getting Rid of Fields Inserted by Third-Party Programs

Third-party programs can be used to affect a document and change what is contained therein. Of course, getting rid of what ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (menu)

Dynamic Worksheet Tab Names

Need a worksheet's name to change based on the contents of a cell? You'll need to rely on a macro to do the changing, but it ...

Discover More

Turning Off Worksheet Tabs

Look at the bottom of a worksheet and chances are you will see tabs for all the worksheets in the current workbook. Want to ...

Discover More

Sheets for Days

Need a quick way to have a worksheet for each day in a month? Here's a macro that makes the worksheet creation a snap.

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}] in your comment text. You’ll be prompted to upload your image when you submit the comment. 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 one less than 4?

2016-12-12 12:10:04

Mike Schommer

Thank you so much for the help! I needed sheets with a weekending date for a little over a year. Excellent help!


2016-10-25 09:00:09

IAIN O\'DONNELL

i AM TRYING TO CREATE ONE FOR A FULL YEAR DAYS 1 - 365 BUT AM STRUGGLING, HAS ANYONE ANY IDEAS?


2016-08-08 15:08:46

falcios

Love this tip.

Can I format this section to have dates be monthday with no space, ex: 0101
What does dsDate = dsDate + 7 do?

For Each sht In Worksheets
sht.Name = Format(dSDate, "dd-mmm-yyyy")
dSDate = dSDate + 7

I've successfully ran it once and it worked. Second time, it starts in the month of April. Don't know what I did differently. Do you know why this is happening?

Thanks in advance.






2016-03-24 13:16:06

Jerome

Excellent tips...Thank you saved me hours of dating tabs.
Thank you,
Jerome.


2013-01-16 06:36:57

Barry Fitzpatrick

The following macro I've found to be slightly better as it copies the first worksheet which effectively becomes a template. It also leaves any other sheets intact as these are often used for summaries, charts, etc. The actual sheet name can be changed in Line 1 to whatever the user desires.

Once each new sheet is created and renamed there's an opportunity to include any week number dependent formulas, constants, etc. e.g. a brought forward values from previous sheet.

Sub YearSheets()

Dim i As Integer
Dim sName As String

sName = "Wk" 'User can specify what the sheet name they want here
i = 1
ActiveSheet.Name = sName & " " & Format(i, "0") 'Renames the "template" sheet

For i = 2 To 52
ActiveSheet.Copy after:=ActiveSheet 'Copies the sheet
ActiveSheet.Name = sName & " " & Format(i, "0") 'renames the sheet

'.......insert any additional code here to modify the new sheet with week number
' dependent formulas,constants, etc. Links to previous sheet (e.g. brought
' forward figures

Next i

End Sub

Be careful of named ranges; in the first (template) worksheet ranges will have "workbook" scope, however copies of the worksheet will have the same named ranges, but the scope will be only within its own worksheet. Formulas that reference a named range will use the range on the same sheet as the formula resides unless preceded with <sheetname> and appropriate syntax. The following will link consecutive sheets together with a "BroughtFowrd" and "CarriedForward" values using cells which are similarly named.

ActiveSheet.Range("BroughtForward").Formula = "='" & sName & " " & i - 1 _
& "'!" & "CarriedForward"

This macro can easily be modified to create 12 monthly sheets (change 51 to 12, and use an appropriate naming convention for each sheet), or similarly for calendar quarters.


2013-01-15 13:50:25

George

ending date of each week for a year.

This worked well however, it will not let you add from one tab to the other.


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.