File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -75,3 +75,44 @@ Public Function Concat(List As Variant) As String
7575 Next i
7676 Concat = Apostrophe & tmpResult & Apostrophe
7777End Function
78+
79+ ''' <summary>
80+ ''' sDate is expected to be an array
81+ ''' https://www.codeguru.com/ShowCode.asp?ID=7369
82+ ''' </summary>
83+ Public Function WEEKNUM (sDate As Variant ) As String
84+ Dim tmpDate As Date
85+
86+ If sDate(0 ) Like "'*'" Then
87+ tmpDate = CDate(Mid(sDate(0 ), 2 , Len(sDate(0 )) - 2 ))
88+ Else
89+ tmpDate = CDate(sDate(0 ))
90+ End If
91+ 'Monday is set as first day of week
92+ Dim lngDate As Long
93+ Dim intWeek As Integer
94+
95+ 'If january 1. is later then thursday, january 1. is not in week 1
96+ If Not Weekday("01/01/" & Year(tmpDate), vbMonday) > 4 Then
97+ intWeek = 1
98+ Else
99+ intWeek = 0
100+ End If
101+ 'Sets long-value for january 1.
102+ lngDate = CLng(CDate("01/01/" & Year(tmpDate)))
103+
104+ 'Finds the first monday of year
105+ lngDate = lngDate + (8 - Weekday("01/01/" & Year(tmpDate), vbMonday))
106+ 'Increases week by week until set date is passed
107+ While Not lngDate > CLng(tmpDate)
108+ intWeek = intWeek + 1
109+ lngDate = lngDate + 7
110+ Wend
111+ 'If the date set is not in week 1, this finds latest week previous year
112+ If intWeek = 0 Then
113+ intWeek = WEEKNUM("31/12/" & Year(tmpDate) - 1 )
114+ End If
115+ WEEKNUM = intWeek
116+ End Function
117+
118+
You can’t perform that action at this time.
0 commit comments