ERLANDSEN DATA CONSULTING Excel & VBA Tips   Informasjon på norsk / Information in Norwegian

These pages are no longer updated and are only available for archive purposes.

Click here to visit the pages with updated information.

Calculate a weeks start date

With the custom function below you can calculate the start date for any given week:

Function WeekStartDate(intWeek As Integer, intYear As Integer) As Date
Dim FromDate As Date, lngAdd As Long
    If intYear < 1 Then intYear = Year(Date) ' the current year
    FromDate = DateSerial(intYear, 1, 1)
    If Weekday(FromDate, vbMonday) > 4 Then lngAdd = 7
    WeekStartDate = FromDate + ((7 * intWeek) - 6) - _
        Weekday(FromDate, vbMonday) + lngAdd
End Function

 

Document last updated 2002-01-26 12:44:38      Printerfriendly version

User comments:
Jes R from Ashton, UK wrote (2005-09-14 21:31:04 CET):
Simpler method, doesn't necessitate VB and also allows for weeks starting Sunday, Monday, . . .
WeekCommencingDate =
DateToCheck -
if((Weekday(DateToCheck)-WeekStartingDayNo)

 

Erlandsen Data Consulting     http://www.erlandsendata.no/   
Excel & VBA Tips   Copyright ©1999-2024    Ole P. Erlandsen   All rights reserved
E-mail Contact Address