Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Week Number Function


Hi all,

I am trying to calculate the week number on a given date. The following
function I obtained from the net;


Code:
--------------------

Function WEEKNR(InputDate As Long) As Integer
Dim A As Integer, B As Integer, C As Long, D As Integer
WEEKNR = 0
If InputDate < 1 Then Exit Function
A = Weekday(InputDate, vbSunday)
B = Year(InputDate + ((8 - A) Mod 7) - 3)
C = DateSerial(B, 1, 1)
D = (Weekday(C, vbSunday) + 1) Mod 7
WEEKNR = Int((InputDate - C - 3 + D) / 7) + 1
End Function

--------------------


This function seems to output the correct value when i do *MsgBox
WEEKNR(Date)* but when i substitute the excel date function for a date
of my own it seems to give me a ByRef error.

The date in the cell is in format 15032006 and i was going the
following;


Code:
--------------------

Dim dateget as date

dateget = Left(Cells(7, 8).Value, 2) & "/" & _
Mid(Cells(7, 8).Value, 3, 2) & "/" & Right(Cells(7, 8).Value, 4)

--------------------


and the error comes when i do *MsgBox WEEKNR(dateget )*

Any ideas guys, loosing my mind today! Thanks


--
gti_jobert
------------------------------------------------------------------------
gti_jobert's Profile: http://www.excelforum.com/member.php...o&userid=30634
View this thread: http://www.excelforum.com/showthread...hreadid=522661

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

Hi gti_jobert

Look here
http://www.rondebruin.nl/weeknumber.htm


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


"gti_jobert" wrote in message
...

Hi all,

I am trying to calculate the week number on a given date. The following
function I obtained from the net;


Code:
--------------------

Function WEEKNR(InputDate As Long) As Integer
Dim A As Integer, B As Integer, C As Long, D As Integer
WEEKNR = 0
If InputDate < 1 Then Exit Function
A = Weekday(InputDate, vbSunday)
B = Year(InputDate + ((8 - A) Mod 7) - 3)
C = DateSerial(B, 1, 1)
D = (Weekday(C, vbSunday) + 1) Mod 7
WEEKNR = Int((InputDate - C - 3 + D) / 7) + 1
End Function

--------------------


This function seems to output the correct value when i do *MsgBox
WEEKNR(Date)* but when i substitute the excel date function for a date
of my own it seems to give me a ByRef error.

The date in the cell is in format 15032006 and i was going the
following;


Code:
--------------------

Dim dateget as date

dateget = Left(Cells(7, 8).Value, 2) & "/" & _
Mid(Cells(7, 8).Value, 3, 2) & "/" & Right(Cells(7, 8).Value, 4)

--------------------


and the error comes when i do *MsgBox WEEKNR(dateget )*

Any ideas guys, loosing my mind today! Thanks


--
gti_jobert
------------------------------------------------------------------------
gti_jobert's Profile: http://www.excelforum.com/member.php...o&userid=30634
View this thread: http://www.excelforum.com/showthread...hreadid=522661



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 142
Default Week Number Function

On Wed, 15 Mar 2006 09:36:58 -0600, gti_jobert
wrote:


Hi all,

I am trying to calculate the week number on a given date. The following
function I obtained from the net;

How do you define week number? For example, Jan 1, 2003 was on Wednesday.
In 2003 is the first day of week 2:
Wednesday Jan 8, or
Sunday Jan 5?
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Week Number Function


Hi,

I have searched through your site before whilst hunting for a solution
to this, theres a calendar .xls but thats no good for me, nor are the
formulas as I need a solution via VBA.

TIA


--
gti_jobert
------------------------------------------------------------------------
gti_jobert's Profile: http://www.excelforum.com/member.php...o&userid=30634
View this thread: http://www.excelforum.com/showthread...hreadid=522661

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Week Number Function


Thanks for all your replys!

I have now substituted and using the function:


Code
-------------------

Function VBAWeekNum(D As Date, FW As Integer) As Integer
VBAWeekNum = CInt(Format(D, "ww", FW))
End Function

-------------------


But I am still getting the ByRef mismiatch error, the date in the cel
is stored as text and in format 16032006.

Any ideas??

--
gti_jober
-----------------------------------------------------------------------
gti_jobert's Profile: http://www.excelforum.com/member.php...fo&userid=3063
View this thread: http://www.excelforum.com/showthread.php?threadid=52266



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Week Number Function


wooops, have just got it working......using that function I split th
date with a "/" and made sure I declared it as date

--
gti_jober
-----------------------------------------------------------------------
gti_jobert's Profile: http://www.excelforum.com/member.php...fo&userid=3063
View this thread: http://www.excelforum.com/showthread.php?threadid=52266

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
Extracting week number from Today() function BillyPilgrim Excel Worksheet Functions 5 August 10th 09 05:56 AM
Week Number Kam Excel Discussion (Misc queries) 2 August 8th 07 02:08 PM
group sales by week and week number Wanna Learn Excel Discussion (Misc queries) 7 November 7th 06 11:44 AM
Week Number Decreenisi Excel Worksheet Functions 3 February 3rd 06 02:56 PM
I need week number in excell from a date, first week must be mini. jPeich Excel Discussion (Misc queries) 4 January 5th 05 01:21 AM


All times are GMT +1. The time now is 12:57 PM.

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"