I have a problem by filling an array in excel vba by using a loop.
Actually I would like to fill the dictionary myitem
the following way:
produkt1
and produkt2
may be both dictionaries.
myitem("productionOrderItems")=Array(produkt1, produkt2).
Since I don't now how many times I have a produkt
I am using a loop to create the dictionary produkt
.
Everytime the dictionary produkt
is created and filled I would like to assign it to an Array
just like I described above.
The following code shows the loop to create the dictionary. But in that case obviously only the last dictionary (i=counter
) is created.
counter
is the amount of products I would like to assign to the Array
.
myitem As New Dictionary
For i = 1 To counter
Dim produkt As New Dictionary
zeile = 2 + i
produkt("id") = Tabelle6.Cells(zeile, 1).Value
Tabelle6.Cells(zeile, 1).Value = ""
produkt("actualWithdrawalQuantity") = Tabelle6.Cells(zeile, 2).Value
Tabelle6.Cells(zeile, 2).Value = ""
produkt("articleId") = Tabelle6.Cells(zeile, 3).Value
Tabelle6.Cells(zeile, 3).Value = ""
produkt("articleNumber") = Tabelle6.Cells(zeile, 4).Value
Tabelle6.Cells(zeile, 4).Value = ""
produkt("createdDate") = Tabelle6.Cells(zeile, 5).Value
Tabelle6.Cells(zeile, 5).Value = ""
produkt("positionNumber") = Tabelle6.Cells(zeile, 6).Value
Tabelle6.Cells(zeile, 6).Value = ""
produkt("quantity") = Tabelle6.Cells(zeile, 7).Value
Tabelle6.Cells(zeile, 7).Value = ""
produkt("targetWithdrawalDate") = Tabelle6.Cells(zeile, 8).Value
Tabelle6.Cells(zeile, 8).Value = ""
produkt("targetWithdrawalQuantity") = Tabelle6.Cells(zeile, 9).Value
Tabelle6.Cells(zeile, 9).Value = ""
myitem("productionOrderItems") = Array(produkt)
Next
Maybe someone has an idea how to solve the problem. Thanks in advance!