Bonjour Jean-Eric.
pmfontaine :
Voici ton code adapté.
J'ai déclaré ton tableau dans les variables.
Et j'ai ajouté la fonction Tri de Boisgontier pour éviter de devoir trier sur ta feuille.
Sub Extraire()
Dim TousLesSites As Integer
Dim N As Integer
Dim i As Integer
Dim tabloBD()
Sheets("FeuilleBilan").Select
Range(Cells(4, 2), Cells(10000, 5)).Select
Selection.ClearContents
For TousLesSites = 2 To 4 Step 2
N = 0
With Sheets("BD")
tabloBD = .Cells(2, 1).Resize(.Cells(Rows.Count, 1).End(xlUp).Row - 1, 3).Value
Tri tabloBD, 1, LBound(tabloBD), UBound(tabloBD)
End With
Set liste = CreateObject("scripting.dictionary")
With Sheets("FeuilleBilan")
For i = LBound(tabloBD) To UBound(tabloBD)
DateObservation = tabloBD(i, 1)
If Not liste.Exists(tabloBD(i, 2) & "#" & tabloBD(i, 3)) Then
liste(tabloBD(i, 2) & "#" & tabloBD(i, 3)) = ""
If tabloBD(i, 2) = .Cells(2, TousLesSites) Then
N = N + 1
.Cells(3 + N, TousLesSites) = tabloBD(i, 1)
.Cells(3 + N, TousLesSites + 1) = tabloBD(i, 3)
End If
End If
Next i
End With
Range("A1").Select
Next TousLesSites
End Sub
Sub Tri(a(), ColTri, gauc, droi) ' Quick sort
ref = a((gauc + droi) \ 2, ColTri)
g = gauc: d = droi
Do
Do While a(g, ColTri) < ref: g = g + 1: Loop
Do While ref < a(d, ColTri): d = d - 1: Loop
If g <= d Then
For k = LBound(a, 2) To UBound(a, 2)
temp = a(g, k): a(g, k) = a(d, k): a(d, k) = temp
Next k
g = g + 1: d = d - 1
End If
Loop While g <= d
If g < droi Then Call Tri(a, ColTri, g, droi)
If gauc < d Then Call Tri(a, ColTri, gauc, d)
End Sub