Loading
Excel.Tips.Net ExcelTips (Menu Interface)

Naming Tabs for Weeks

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.

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.

Related Tips:

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!

 

Leave your own comment:

*Name:
Email:
  Notify me about new comments ONLY FOR THIS TIP
Notify me about new comments ANYWHERE ON THIS SITE
Hide my email address
*Text:
*What is 5+3 (To prevent automated submissions and spam.)
 
 
           Commenting Terms

Comments for this tip:

IAIN O'DONNELL    25 Oct 2016, 09:00
i AM TRYING TO CREATE ONE FOR A FULL YEAR DAYS 1 - 365 BUT AM STRUGGLING, HAS ANYONE ANY IDEAS?
falcios    08 Aug 2016, 15:08
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.





Jerome    24 Mar 2016, 13:16
Excellent tips...Thank you saved me hours of dating tabs.
Thank you,
Jerome.
Barry Fitzpatrick    16 Jan 2013, 06:36
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.
George    15 Jan 2013, 13:50
ending date of each week for a year.

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

Our Company

Sharon Parq Associates, Inc.

About Tips.Net

Contact Us

 

Advertise with Us

Our Privacy Policy

Our Sites

Tips.Net

Beauty and Style

Cars

Cleaning

Cooking

DriveTips (Google Drive)

ExcelTips (Excel 97–2003)

ExcelTips (Excel 2007–2016)

Gardening

Health

Home Improvement

Money and Finances

Organizing

Pests and Bugs

Pets and Animals

WindowsTips (Microsoft Windows)

WordTips (Word 97–2003)

WordTips (Word 2007–2016)

Our Products

Helpful E-books

Newsletter Archives

 

Excel Products

Word Products

Our Authors

Author Index

Write for Tips.Net

Copyright © 2016 Sharon Parq Associates, Inc.