Does anyone here knows how to combine data from 1 list in a document to another list in another documentList1 and List2 is a text field that accepts multiple value
Private QtyList List As Double
Sub AddLines(varVals As Variant)
Dim dblQty As Double
Dim strOfWhat As String
Dim strLine As String
Forall valu In varVals
strLine = Fulltrim(valu)
dblQty = Cdbl(Strleft(strLine, " "))
strOfWhat = Strright(strLine, " ")
If Iselement(QtyList(strOfWhat)) Then
QtyList(strOfWhat) = QtyList(strOfWhat) + dblQty
Else
QtyList(strOfWhat) = dblQty
End If
End Forall
End Sub
Public Property Get Result As Variant
Dim strOutput As String
Forall qty In QtyList
strOutput = strOutput & {
} & qty & " " & Listtag(qty)
End Forall
Result = Split(Mid$(strOutput, 2), {
})
End Property
End Class
…
Dim adder As New QuantityTotaler
…
adder.AddLines(doc1.fieldname(0))
adder.AddLines(doc2.fieldname(0))
doc3.fieldname = adder.Result
Of course, this only works insofar as the same item is always listed with the same unit of measurement. If instead of “pcs” always, you have some “cups” and some “gallons” of the same thing, this code doesn’t know how to combine those into a single line.
Does this code adds if the value is the same with the other list? or does it sum all for list 1 and adds total of list2?
Coz what i need to know is get list1, then get list2 and run thru each items in list2 comparing each items to list1 and adds if found a match, otherwise i need to append the data in list2 that is not listed in list1
Subject: It does what you asked for. Try it and see.
The QtyList is a List value, which means that it contains a collection of strings with associated values of a specified type (in this case, “Double” floating point numbers). In this case the string values are the what you have a quantity of and the Double values are how much.