Help to correct the cumulative code by quantity. Wrong result when sum =0

Excelpromax123

Board Regular
Joined
Sep 2, 2021
Messages
167
Office Version
  1. 2010
Platform
  1. Windows
Hello everyone. I have used the code to accumulate the quantity by item code. Code is wrong when adding item code "AAA", the correct result is 0 (-11.67 + 11 + 0.67 = 0 ). But the result of running code is 1.11022E-16 . Thanks everyone for fixing the above error. Sincerely thank

VBA Code:
 Sub sumtotal()
On Error Resume Next
  Dim Dic As Object, dArr As Variant, arr As Variant, Tmp As Variant, s As Variant
  Dim i As Long, J As Integer, K As Long, ik As Long, key As String, b As Long
  Set Dic = CreateObject("Scripting.dictionary")
  dArr = Range("b4:b100").Value
  ReDim arr(1 To UBound(dArr), 1 To 3)
  For i = 1 To UBound(dArr)
      Tmp = Split(dArr(i, 1), ";")
      For J = LBound(Tmp) To UBound(Tmp)
          s = Split(Tmp(J), "*")
          If UBound(s) = 2 Then
              key = s(0)
              If Not Dic.Exists(key) Then
                  K = K + 1
                  Dic.Add key, K
                  arr(K, 1) = key
              End If
              ik = Dic.Item(key)
              arr(ik, 2) = arr(ik, 2) + CDbl(s(1))
              arr(ik, 3) = arr(ik, 3) + CDbl(s(2))
          End If
      Next J
  Next i
Range("D4:F1100").ClearContents
Range("D4:F1100").Resize(K) = arr
End Sub

1680962422351.png
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Forum statistics

Threads
1,215,960
Messages
6,127,943
Members
449,412
Latest member
montand

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top