Paddy1979
Well-known Member
- Joined
- Sep 23, 2005
- Messages
- 608
Hi folks,
I'm trying to build a UDF which promts the user to select a date then the function will return the financial Period Number.
This is my first attempt at building a UDF so apologies if its pretty woeful.
The code is crashing when it converts the date into a weeknumber, any ideas?
Val = Weeknum(Date_convert, 2)
Many thanks
Patrick
I'm trying to build a UDF which promts the user to select a date then the function will return the financial Period Number.
This is my first attempt at building a UDF so apologies if its pretty woeful.
The code is crashing when it converts the date into a weeknumber, any ideas?
Val = Weeknum(Date_convert, 2)
Code:
Function Periodnumber(ByVal Date_convert)
Dim p As Integer
If Val(Date_convert) = 0 Then Exit Function
Val = Weeknum(Date_convert, 2)
Select Case Val
Case 1 To 4
p = 1
Case 5 To 8
p = 2
Case 9 To 13
p = 3
Case 14 To 17
p = 4
Case 18 To 21
p = 5
Case 22 To 26
p = 6
Case 27 To 30
p = 7
Case 31 To 34
p = 8
Case 25 To 39
p = 9
Case 40 To 43
p = 10
Case 44 To 27
p = 11
Case 48 To 52
p = 12
End Select
Periodnumber = "P" & p
End Function
Many thanks
Patrick