Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default weeknumber function in vba(excel) doesn't work

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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,316
Default weeknumber function in vba(excel) doesn't work

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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,123
Default weeknumber function in vba(excel) doesn't work

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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,316
Default weeknumber function in vba(excel) doesn't work

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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,651
Default weeknumber function in vba(excel) doesn't work

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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default weeknumber function in vba(excel) doesn't work

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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,651
Default weeknumber function in vba(excel) doesn't work

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
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
Earliest date using WEEKNUMBER Jock Excel Worksheet Functions 3 September 17th 07 10:17 AM
Which excel function would work best? Paul T Excel Worksheet Functions 1 March 1st 06 07:19 PM
weeknumber John Britto Excel Discussion (Misc queries) 6 October 7th 05 04:23 PM
Formula to get the current weeknumber Ludde Excel Discussion (Misc queries) 2 September 10th 05 12:17 PM
Weeknumber in Excel Gunnar From Sweden Excel Discussion (Misc queries) 1 January 5th 05 08:29 AM


All times are GMT +1. The time now is 12:18 AM.

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

About Us

"It's about Microsoft Excel"