Function nb_jours_ouvrés(date_début, date_fin)
' contrôle dates ------------------------------
If Not IsDate(date_début) Then
MsgBox "la date début n'est pas une date "
Exit Function
End If
If Not IsDate(date_fin) Then
MsgBox "la date fin n'est pas une date "
Exit Function
End If
If date_fin < date_début Then
MsgBox "la date fin n'est pas supérieure à la date début "
Exit Function
End If
' nb jours calendaires ------------------------------
nb_jours_calendaires = date_fin - date_début
' détection jours non ouvrés ------------------------------
nb_jours_non_ouvrés = 0
For date_i = date_début To date_fin
If DatePart("w", date_i, vbMonday) = 6 _
Or DatePart("w", date_i, vbMonday) = 7 _
Or DatePart("d", date_i) = DatePart("d", premier_jour_année(Year(date_i))) _
Or DatePart("d", date_i) = DatePart("d", lundi_Paques(Year(date_i))) _
Or DatePart("d", date_i) = DatePart("d", premier_mai(Year(date_i))) _
Or DatePart("d", date_i) = DatePart("d", huit_mai(Year(date_i))) _
Or DatePart("d", date_i) = DatePart("d", jeudi_Ascension(Year(date_i))) _
Or DatePart("d", date_i) = DatePart("d", lundi_Pentecote(Year(date_i))) _
Or DatePart("d", date_i) = DatePart("d", fête_nationale(Year(date_i))) _
Or DatePart("d", date_i) = DatePart("d", onze_novembre(Year(date_i))) _
Or DatePart("d", date_i) = DatePart("d", noël(Year(date_i))) Then
nb_jours_non_ouvrés = nb_jours_non_ouvrés + 1
End If
Next date_i
'---------------------------------------------------------------
' nb jours ouvrés ------------------------------
nb_jours_ouvrés = nb_jours_calendaires - nb_jours_non_ouvrés
End Function
Function premier_jour_année(année As Integer) As String
premier_jour_année = DateSerial(année, 1, 1)
End Function
Function premier_mai(année As Integer) As String
premier_mai = DateSerial(année, 5, 1)
End Function
Function huit_mai(année As Integer) As String
huit_mai = DateSerial(année, 5, 8)
End Function
Function fête_nationale(année As Integer) As String
fête_nationale = DateSerial(année, 7, 14)
End Function
Function onze_novembre(année As Integer) As String
onze_novembre = DateSerial(année, 11, 11)
End Function
Function noël(année As Integer) As String
noël = DateSerial(année, 12, 25)
End Function
Function lundi_Paques(année As Integer) As String
lundi_Paques = DateAdd("d", 1, date_Paques(année))
End Function
Function jeudi_Ascension(année As Integer) As String
jeudi_Ascension = DateAdd("d", 39, date_Paques(année))
End Function
Function lundi_Pentecote(année As Integer) As String
lundi_Pentecote = DateAdd("d", 50, date_Paques(année))
End Function
Function date_Paques(année As Integer) As String
Dim a, b, c, d, e, f, g, h, i, k, l, m, r, mois, jour
a = année Mod 19
b = année \ 100
c = année Mod 100
d = b \ 4
e = b Mod 4
f = (b + 8) \ 25
g = (b - f + 1) \ 3
h = (19 * a + b - d - g + 15) Mod 30
i = c \ 4
k = c Mod 4
l = (32 + 2 * e + 2 * i - h - k) Mod 7
m = (a + 11 * h + 22 * l) \ 451
r = (114 + h + l - 7 * m)
mois = r \ 31
jour = r Mod 31 + 1
date_Paques = DateSerial(année, mois, jour)
End Function
Sub Ellipse1_QuandClic()
'
Dim ID_Cas As String
ID_Cas = Range("A3").Value
Date1 = Range("C3").Value
For i = 4 To Sheets("Rapport1").Range("A" & Application.Rows.Count).End(xlUp).Row + 1
If Range("A" & i) <> ID_Cas Then
Date2 = Range("C" & i - 1)
Jour_ouvres = nb_jours_ouvrés(Date1, Date2)
Range("D" & i - 1) = Jour_ouvres
Range("D" & i - 1).NumberFormat = "[h]:mm:ss"
ID_Cas = Range("A" & i)
Date1 = Range("C" & i)
End If
Next i
For b = i - 1 To 1 Step -1
If Cells(b, 4).Value = "A faire via une maccro Excel" Then
Rows(b).Delete
End If
Next b
For i = 3 To Sheets("Rapport1").Range("A" & Application.Rows.Count).End(xlUp).Row
CPT = CPT + 1
Next i
MsgBox "Il y a " & CPT & " tickets à facturer."
End Sub