Wilder1626
asked on
week number issue in macro
Hello all
I have this macro where it enter in a cell the week's number followed by the date.
The problem i have is that the week's number is not good.
If i take for example, today, we are on week 50.
But is i activate the macro, the result i have is: Semaine:52 Sunday Dec 18 2011
How i can fix this?
Thanks again
I have this macro where it enter in a cell the week's number followed by the date.
The problem i have is that the week's number is not good.
If i take for example, today, we are on week 50.
But is i activate the macro, the result i have is: Semaine:52 Sunday Dec 18 2011
How i can fix this?
Thanks again
Private Sub Calendar1_Click()
Dim t As Long
t = DateSerial(Year(D + (8 - Weekday(D)) Mod 7 - 3), 1, 1)
NumSemaine = ((D - t - 3 + (Weekday(t) + 1) Mod 7)) \ 7 + 1
Unload Me
ActiveCell.Value = "Semaine:" & NumSemaine & " " & Format(Calendar1.Value, "dddd mmm dd yyyy")
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can also tyr using buildin Excel funtion WEEKNUM().
NumSemaine = WorksheetFunction.WeekNum(
Or Format. :
Format(D,"ww")
I assumed "D" is your date.
ASKER
Hello all
Thanks, i will go with this one.
Now it work pretty good.
Thanks, i will go with this one.
Now it work pretty good.
I believe you want the ISO week number (international standard).
So you should implement:
Public Function IsoWeekNumber(InDate As Date) As Long
IsoWeekNumber = DatePart("ww", InDate, vbMonday, vbFirstFourDays)
End Function