Salut Nextia,
pour confirmation, dans 'BDD' actuelle :
- le n° matricule = Colonne [D:D] "Identifiant agent" ?
- jour de prise = Colonne [S:S] "Date/heure de la consommation" ?
- produit consommé = Colonne [Z:Z] "Produit consommé" ?
Dans ce cas, essaye ceci.
Private Sub cmdGO_Click()
'
Dim sWkABS As Worksheet
Dim tBDD, tABS, lgRow1&, lgRow2&
'
'On Error Resume Next
Set sWkABS = Worksheets("Absence salariés")
Application.EnableEvents = False
Application.ScreenUpdating = False
'
Call Tri(2)
T = Timer
lgRow1 = 1
tBDD = Range("A2:AG" & Range("C" & Rows.Count).End(xlUp).Row + 1).Value
tABS = sWkABS.Range("A2:O" & sWkABS.Range("B" & Rows.Count).End(xlUp).Row).Value
'
For x = 1 To UBound(tBDD, 1)
If tBDD(x, 3) <> "" And tBDD(x, 15) <> "" Then
For y = lgRow1 To UBound(tABS, 1)
If CLng(tABS(y, 2)) = CLng(tBDD(x, 4)) Then
lgRow2 = y
If DateValue(tBDD(x, 19)) >= CDate(tABS(y, 11)) And DateValue(tBDD(x, 19)) <= CDate(tABS(y, 12)) Then
tBDD(x, 32) = "OUI"
tBDD(x, 33) = tABS(y, 10)
tABS(y, 15) = CInt(tABS(y, 15)) + 1
If DateValue(tBDD(x, 19)) = CDate(tABS(y, 12)) And tBDD(x, 26) = "Gazole" Then tBDD(x, 32) = "OUI !"
End If
'
If CLng(tABS(y + 1, 2)) <> CLng(tBDD(x, 4)) And lgRow2 > 0 Then
If CLng(tBDD(x + 1, 4)) <> CLng(tBDD(x, 4)) Then _
lgRow1 = lgRow2 + 1: _
lgRow2 = 0
Exit For
End If
End If
Next
End If
Next
Range("A2").Resize(UBound(tBDD, 1), UBound(tBDD, 2)).Value = tBDD
sWkABS.Range("A2").Resize(UBound(tABS, 1), UBound(tABS, 2)).Value = tABS
'MsgBox Timer - T
Columns("AF:AG").AutoFit
Me.cmdGO.Left = [AG1].Left + 2
'
Application.EnableEvents = True
Application.ScreenUpdating = True
'On Error GoTo 0
'
End Sub
A+