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
| Sub essai()
Dim MyArray1(2, 2)
MyArray1(0, 0) = "ID"
MyArray1(0, 1) = "Client"
MyArray1(0, 2) = "Prix"
MyArray1(1, 0) = "ID1"
MyArray1(1, 1) = "Client A"
MyArray1(1, 2) = 20
MyArray1(2, 0) = "ID2"
MyArray1(2, 1) = "Client B"
MyArray1(2, 2) = 30
Dim MyArray2(2, 1)
MyArray2(0, 0) = "ID"
MyArray2(0, 1) = "Quantité"
MyArray2(1, 0) = "ID2"
MyArray2(1, 1) = 5
MyArray2(2, 0) = "ID1"
MyArray2(2, 1) = 2
'[A2].Resize(UBound(MyArray1) + 1, UBound(MyArray1, 2) + 1) = MyArray1
'[G2].Resize(UBound(MyArray2) + 1, UBound(MyArray2, 2) + 1) = MyArray2
Dim TblResult(2, 4)
Set d = CreateObject("scripting.dictionary")
For i = 0 To UBound(MyArray2)
d(MyArray2(i, 0)) = MyArray2(i, 1)
Next i
For i = 1 To UBound(MyArray1)
For k = 0 To 2
TblResult(i, k) = MyArray1(i, k)
Next k
TblResult(i, 3) = d(MyArray1(i, 0))
TblResult(i, 4) = d(MyArray1(i, 0)) * TblResult(i, 2)
Next i
For k = 0 To 2: TblResult(0, k) = MyArray1(0, k): Next k
TblResult(0, 3) = MyArray2(0, 1)
TblResult(0, 4) = MyArray2(0, 1) & "*" & MyArray1(0, 2)
[K2].Resize(UBound(TblResult) + 1, UBound(TblResult, 2) + 1) = TblResult
End Sub |
Partager