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
| Public Sub Calcul()
Dim shNom As Excel.Worksheet
Dim NumLignNom As Long
Dim TabNomNom() As Variant, TabMontantNom() As Variant
Dim shObjet As Excel.Worksheet
Dim NumLignObj As Long
Dim TabNomObjet() As Variant, TabMontantObjet() As Variant
Dim L As Long, M As Long
Set shNom = Application.ThisWorkbook.Worksheets(3)
Set shObjet = Application.ThisWorkbook.workshets(2)
NumLignNom = shNom.Range("A1").CurrentRegion.Rows.Count
TabNomNom() = shNom.Range("I2:I" & NumLignNom).Value
TabMontantNom = shNom.Range("W2:Z" & NumLignNom).Value
NumLignObj = shObjet.Range("A1").CurrentRegion.Rows.Count
TabNomObjet() = shObjet.Range("S2:S" & NumLignObj).Value
TabMontantObjet() = shObjet.Range("P2:Q" & NumLignObj).Value
For L = LBound(TabNomNom, 1) To UBound(TabNomNom, 1)
TabMontantNom(L, 1) = 0
TabMontantNom(L, 2) = 0
TabMontantNom(L, 3) = 0
For M = LBound(TabNomObjet, 1) To UBound(TabNomObjet, 1)
If TabNomNom(L, 1) = TabNomObjet(M, 1) Then
TabMontantNom(L, 1) = TabMontantNom(L, 1) + 1
TabMontantNom(L, 2) = TabMontantNom(L, 2) + TabMontantObjet(M, 1)
TabMontantNom(L, 3) = TabMontantNom(L, 3) + TabMontantObjet(M, 2)
End If
Next M
Next L
shNom.Range("W2:Z" & NumLignNom).Value = TabMontantNom
Set shNom = Nothing
Set shObjet = Nothing
Erase TabNomNom
Erase TabMontantNom
Erase TabNomObjet
Erase TabMontantObjet
End Sub |
Partager