Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
How to get a proper weeknum function in vba working?
I'm familiar with the weeknum function in the ordinary worksheet, but in vba it's a different story. Has anyone suggestions how to generate the weeknumber by the means of a function in vba? Many thanks in advance. |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Use the date part function
DatePart(Interval, Date DatePart("ww",date) will produce the week number -- Kevin Backmann "vba_kraker" wrote: How to get a proper weeknum function in vba working? I'm familiar with the weeknum function in the ordinary worksheet, but in vba it's a different story. Has anyone suggestions how to generate the weeknumber by the means of a function in vba? Many thanks in advance. |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Hi
See this article with two VBA functions http://msdn2.microsoft.com/en-us/library/bb277364.aspx See also http://www.rondebruin.nl/weeknumber.htm -- Regards Ron de Bruin http://www.rondebruin.nl/tips.htm "vba_kraker" wrote in message ... How to get a proper weeknum function in vba working? I'm familiar with the weeknum function in the ordinary worksheet, but in vba it's a different story. Has anyone suggestions how to generate the weeknumber by the means of a function in vba? Many thanks in advance. |
#4
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Hey Ron, thanks for the excellent information.
-- Kevin Backmann "Ron de Bruin" wrote: Hi See this article with two VBA functions http://msdn2.microsoft.com/en-us/library/bb277364.aspx See also http://www.rondebruin.nl/weeknumber.htm -- Regards Ron de Bruin http://www.rondebruin.nl/tips.htm "vba_kraker" wrote in message ... How to get a proper weeknum function in vba working? I'm familiar with the weeknum function in the ordinary worksheet, but in vba it's a different story. Has anyone suggestions how to generate the weeknumber by the means of a function in vba? Many thanks in advance. |
#5
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
On Wed, 19 Sep 2007 07:26:02 -0700, vba_kraker
wrote: How to get a proper weeknum function in vba working? I'm familiar with the weeknum function in the ordinary worksheet, but in vba it's a different story. Has anyone suggestions how to generate the weeknumber by the means of a function in vba? Many thanks in advance. To mimic the Excel worksheet function WEEKNUM, you may use this UDF: =========================== Function VBWeeknum(dt As Date, _ Optional FirstDayOfWeek As Integer = 1) 'VB Replacement for WEEKNUM worksheet function Select Case FirstDayOfWeek Case 1 To 2 VBWeeknum = DatePart("ww", dt, FirstDayOfWeek, vbFirstJan1) Case Else VBWeeknum = CVErr(xlErrNum) End Select End Function ================================= To generate a weeknumber in accordance with ISO standards, you may use this UDF: ========================================= Function ISOWeeknum(d1 As Date) As Integer ' Daniel Maher Dim d2 As Long d2 = DateSerial(Year(d1 - Weekday(d1 - 1) + 4), 1, 3) ISOWeeknum = Int((d1 - d2 + Weekday(d2) + 5) / 7) End Function ============================= --ron |
#6
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Thanx Ron, the first UDF did the trick!
-- Regards, Adrian "vba_kraker" wrote: How to get a proper weeknum function in vba working? I'm familiar with the weeknum function in the ordinary worksheet, but in vba it's a different story. Has anyone suggestions how to generate the weeknumber by the means of a function in vba? Many thanks in advance. |
#7
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
On Thu, 20 Sep 2007 01:30:01 -0700, vba_kraker
wrote: Thanx Ron, the first UDF did the trick! Glad to help. Thanks for the feedback. --ron |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Earliest date using WEEKNUMBER | Excel Worksheet Functions | |||
Which excel function would work best? | Excel Worksheet Functions | |||
weeknumber | Excel Discussion (Misc queries) | |||
Formula to get the current weeknumber | Excel Discussion (Misc queries) | |||
Weeknumber in Excel | Excel Discussion (Misc queries) |