Thread: Weeknum
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Ron Rosenfeld Ron Rosenfeld is offline
external usenet poster
 
Posts: 5,651
Default Weeknum

On Fri, 16 Sep 2005 16:14:42 -0500, Baapi
wrote:


How to mimic the "Weeknum" function of Excel in the Script? :)


This comes close:

===============
Function VBWeeknum(dt As Date, _
Optional FirstDayOfWeek As Integer = 1) As Integer

VBWeeknum = DatePart("ww", dt, FirstDayOfWeek, vbFirstJan1)
End Function
================

One difference is that the worksheet function WEEKNUM only accepts Sunday or
Monday as being the first day of the week, whereas this UDF can accept any day
as being day 1.

So if you wanted to truly mimic the Weeknum function, you might check that
FirstDayOfWeek is 1 or 2, and if not, return a #NUM! error.


--ron