#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Weeknum


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

--
Baap
-----------------------------------------------------------------------
Baapi's Profile: http://www.excelforum.com/member.php...fo&userid=2733
View this thread: http://www.excelforum.com/showthread.php?threadid=46836

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Weeknum

Hi Baapi

See
http://www.rondebruin.nl/weeknumber.htm

This part
http://www.rondebruin.nl/weeknumber.htm#information
On Chip's site you find one for the Excel Weeknum


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Baapi" wrote in message
...

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


--
Baapi
------------------------------------------------------------------------
Baapi's Profile: http://www.excelforum.com/member.php...o&userid=27333
View this thread: http://www.excelforum.com/showthread...hreadid=468369



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Weeknum


I have a very limited access to internet and the site you have referre
to is blocked under "Free Wares" category.

Anyway, in the mean while I thought of the following logic. But, I'
not sure if this is the perfect one and will work under al
conditions.

(DateSerial (Year(X), Month(X), Day(X) ) - DateSerial (Year(X), 1, 0
)/ 7

Comments? Suggestions

--
Baap
-----------------------------------------------------------------------
Baapi's Profile: http://www.excelforum.com/member.php...fo&userid=2733
View this thread: http://www.excelforum.com/showthread.php?threadid=46836

  #4   Report Post  
Posted to microsoft.public.excel.programming
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
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Weeknum

On Fri, 16 Sep 2005 22:15:27 -0400, Ron Rosenfeld
wrote:

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


Thanks to Norman Jones, we can now do a better job of mimicking the WEEKNUM
function, including errors for invalid entries:

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

Select Case FirstDayOfWeek
Case 1 To 2
VBWeeknum = DatePart("ww", dt, FirstDayOfWeek, vbFirstJan1)
Case Else
VBWeeknum = CVErr(xlErrNum)
End Select
End Function
==================================


--ron


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Weeknum

On Fri, 16 Sep 2005 18:17:53 -0500, Baapi
wrote:


I have a very limited access to internet and the site you have referred
to is blocked under "Free Wares" category.

Anyway, in the mean while I thought of the following logic. But, I'm
not sure if this is the perfect one and will work under all
conditions.

(DateSerial (Year(X), Month(X), Day(X) ) - DateSerial (Year(X), 1, 0 )
)/ 7

Comments? Suggestions?


Your formula will give different results than Excel's WEEKNUM function unless
the year starts on a Sunday.

See my other responses for some other ideas.


--ron
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Weeknum help SoSoExcelGuy Excel Worksheet Functions 2 August 1st 06 03:14 PM
weeknum gone ?? KrunoG Excel Worksheet Functions 2 June 27th 06 10:11 AM
WEEKNUM RonB Excel Worksheet Functions 3 April 12th 06 11:37 AM
Weeknum Mike D. Excel Worksheet Functions 4 February 14th 06 08:44 PM
WEEKNUM() Ciara Excel Discussion (Misc queries) 5 April 13th 05 12:09 PM


All times are GMT +1. The time now is 05:38 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"