|
|
The script works perfect, Thanks
Edward
"Ron Rosenfeld" wrote:
On Fri, 11 Mar 2005 04:55:04 -0800, Edward
wrote:
As a result Excel 2003 shows 8 (week number) for 15.2.2005, but the correct
result is 7.
For Year 2004 the answer is correct.
Actually, if you read the documentation in HELP, you will see that the Excel
WEEKNUM function does NOT give the ISO week number, which is probably what you
are expecting. So to talk about "correct" you must first define what your
standards are. WEEKNUM in Excel does give the "correct" answer -- at least it
complies with it's own definition which is NOT the SAME definition as the ISO
standard.
If you want to obtain an ISO compliant week number, I think the easiest way is
to use either a VBA User Defined Function or, if you have Longre's morefunc.xll
add-in, you can use his ISO.WEEKNUM function.
Below is a VBA routine. To enter it, <alt-F11 opens the VB Editor. Ensure
your project is highlighted in the project explorer window, then Insert/Module
and paste the code below into the window that opens.
You can then use =isoweeknum(date) in your workbook.
================================
Function ISOWeeknum(dt As Date) As Integer
ISOWeeknum = DatePart("ww", dt, vbMonday, vbFirstFourDays)
If ISOWeeknum 52 Then
If DatePart("ww", dt + 7, vbMonday, vbFirstFourDays) = 2 Then
ISOWeeknum = 1
End If
End If
End Function
===============================
--ron
|