1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| Sub RepriseCommande(Cde As String)
Dim CdeArray As Variant, ArtArray As Variant, QteArray As Variant
Dim r As Range, i As Long, j As Long
If MsgBox("Vider la commande actuelle et reprendre celle choisie?", vbYesNo + vbDefaultButton2, "Oui/non") = vbNo Then Exit Sub
Range("C6:C7,D3:F5,C12:D30").ClearContents
Set r = Range("tHisto[N° Cde]").Find(What:=Cde, LookAt:=xlWhole)
Range("C6") = r
Range("C7") = r.Offset(0, -6)
Range("D3") = r.Offset(0, -4)
CdeArray = Range("tHisto[N° Cde]").Value ' récupère les valeurs dans un tableau 2D (1 colonne)
ArtArray = Range("tHisto[Désignation]").Value ' récupère les valeurs dans un tableau 2D (1 colonne)
QteArray = Range("tHisto[Qté]").Value ' récupère les valeurs dans un tableau 2D (1 colonne)
j = 1
For i = LBound(CdeArray, 1) To UBound(CdeArray, 1) ' boucle sur les lignes du tableau
If CdeArray(i, 1) = Cde Then ' CdeArray(i, 1) correspond à la cellule de la i-ème ligne, 1ère colonne
Range("C" & 11 + j) = ArtArray(i, 1)
Range("D" & 11 + j) = QteArray(i, 1)
j = j + 1
End If
Next i
End Sub |
Partager