1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| Sub test()
Dim w_Actif As Workbook, w_Donnees As Workboo, VA, Coll As New Collection, i As Long, Lig As Long
Set w_Actif = ThisWorkbook
Set w_Donnees = Workbooks.Open(w_Actif.Path & "\ETAT DE STOCKS_AUTOMATE.xls")
With w_Donnees
With .Sheets("STOCK")
VA = .Range("B2:E" & .Cells(.Rows.Count, 3).End(xlUp).Row).Value
End With
.Close False
End With
Set w_Donnees = Nothing
On Error Resume Next
For i = LBound(VA) To UBound(VA)
If VA(i, 2) > "" Then 'par précaution je ne connais pas les données - VA(i, 2) => désignation
Coll.Add i, CStr(VA(i, 2)) ' enregistrement dans la collection de la ligne (i) dont l'index est le nom de la désignation -> CStr(VA(i, 2))
If Err Then Err.Clear ' par précaution je ne connais pas les données
End If
Next
With w_Actif
'.Worksheets.Add: .ActiveSheet.Name = "STOCK" ' <= Facultatif car utilsation d'une collection et d'un variable tableau
With .Sheets("VPC STANDARD")
Application.ScreenUpdating = False
For i = 2 To .Cells(.Rows.Count, 1).End(xlUp).Row
Lig = Coll(CStr(.Cells(i, 1))) 'on vérifie que la "désignation" existe dans la collection
' si y a pas d'erreur , on récupère la ligne (LIig correspondante dans la variable tableau afin de récupérer les valeurs de NUM_PARUTION et POIDS_PARUTION
If Err Then
Err.Clear
Else
.Cells(i, 12) = VA(Lig, 1) ' NUM_PARUTION
.Cells(i, 13) = VA(Lig, 4) ' POIDS_PARUTION
End If
Next
Application.ScreenUpdating = True
End With
End With
On Error GoTo 0
Set w_Actif = Nothing
End Sub |
Partager