Correct the function WEEKNUMBER

G

Guest

The function weeknumber does not work properly. When typing Jan 1 2005 it
should display 53 and not 1, when i typ jan 3rd (in colum 1) and
=weeknumber(a2) in collum b it should display 1 and not 2. because the weeks
in 2004 is 53 and not 52, is this my mistake or is this with excel that only
counts up to week 52.
I hope you can change this.
 
R

Ron Rosenfeld

On Sat, 6 Nov 2004 09:05:01 -0800, Eric Wessels <Eric
The function weeknumber does not work properly. When typing Jan 1 2005 it
should display 53 and not 1, when i typ jan 3rd (in colum 1) and
=weeknumber(a2) in collum b it should display 1 and not 2. because the weeks
in 2004 is 53 and not 52, is this my mistake or is this with excel that only
counts up to week 52.
I hope you can change this.

Perhaps what you are looking for is the ISO weeknumber standard. This is not
the same as the weeknum function in excel.

Here is a UDF that can compute the ISO weeknumber:

=====================
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
===================

To enter this UDF, <alt-F11> opens the VB Editor.

Ensure your project is highlighted in the Project Explorer, then Insert/Module
and paste the above code into the window that opens.

To use it: =isoweeknum(dt) where dt is either a date or a cell reference that
contains a date.


--ron
 
G

Guest

The hint is very usefull, however this should be a natural part of the Excel
formular portfolio.
 
M

Myrna Larson

Excel *has* a WEEKNUM function. It has limitations. If you want to learn about
them, check the link given. If not, use it as-is.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top