Selected Answer
Hi again Leopard
The problem arises in the third element of your array b, e.g. b(4,3). This is text (for some reason) so the first line in bold (in the code extract below) combines the text (e.g. "9" & "5" = "95") rather than add the numbers (e.g. 9 + 5 = 14).
This is easily fixed by converting each text in that line to the Double data type using the CDbl conversion command- see third line in bold below:
For idx = 1 To wb2.Sheets.Count
Set sh = wb2.Sheets(idx)
a = sh.Range("A2", sh.Range("G" & Rows.Count).End(3)).Value
For i = 1 To UBound(a, 1)
If (a(i, 1) = "") + (IsNumeric(a(i, 1))) Then
ky = a(i, 7) & "|" & a(i, 4)
If Not dic.exists(ky) Then
y = y + 1
dic(ky) = y
End If
nRow = dic(ky)
b(nRow, 1) = nRow
b(nRow, 2) = a(i, 7)
' b(nRow, 3) = b(nRow, 3) + a(i, 5)
' replace the above with this...
b(nRow, 3) = CDbl(b(nRow, 3)) + CDbl(a(i, 5))
b(nRow, 4) = a(i, 4)
b(nRow, 5) = b(nRow, 3) * b(nRow, 4)
tQty = tQty + a(i, 5)
tBal = tBal + (a(i, 4) * a(i, 5))
End If
Next
Next
That change is made in the revised DA file attached and should now give correct sums.