Hi,
I need to treat my problem when show TOTAL row to sum columns I:L .
I put the right way how should be , but when running the macro will not sum and show TOTAL word in error location.
thanks
Hi,
I need to treat my problem when show TOTAL row to sum columns I:L .
I put the right way how should be , but when running the macro will not sum and show TOTAL word in error location.
thanks
AHHGGJ-1 Total 3,200.00 0.00
AHHGGJ-2 Total 3,000.00 1,300.00
AHHGGJ-3 Total 2,000.00 0.00
AHHGGJ-4 Total 1,500.00 0.00
AHHGGJ-5 Total 1,000.00 0.00
Hasson
There are two problems with your code:
In the attached, revised file, I've modified your code as follows, commenting out some lines and adding comments plus changes in bold:
Sub Combine_Customers()
Dim ar, ar2, a, j As Long
ar = Sheets("CLS").Cells(1).CurrentRegion.Value2
ar2 = Sheets("VB").Cells(1).CurrentRegion
With CreateObject("scripting.dictionary")
'For j = 2 To UBound(ar) - 1
' add all Names to dictionary
For j = 2 To UBound(ar)
.Item(ar(j, 2)) = Array(ar(j, 1), ar(j, 2), ar(j, 3), 0, 0, ar(j, 3))
Next j
For j = 2 To UBound(ar2) ' - 1
If .exists(ar2(j, 2)) Then
a = .Item(ar2(j, 2))
a(3) = a(3) + ar2(j, 4)
a(4) = a(4) + ar2(j, 5)
a(5) = IIf(a(2) = 0, a(3) - a(4), a(2) + a(3) - a(4))
.Item(ar2(j, 2)) = a
Else
.Item(ar2(j, 2)) = Array(ar2(j, 1), ar2(j, 2), 0, ar2(j, 4), ar2(j, 5), ar2(j, 6))
End If
Next j
'.Item(.Count) = Array("TOTAL", "", ar(UBound(ar), 3), ar2(UBound(ar2), 4), ar2(UBound(ar2), 5), Application.Sum(Application.Index(.items, 0, 6)))
' sum all columns. not just Total column
.Item(.Count) = Array("TOTAL", "", _
Application.Sum(Application.Index(.Items, 0, 3)), _
Application.Sum(Application.Index(.Items, 0, 4)), _
Application.Sum(Application.Index(.Items, 0, 5)), _
Application.Sum(Application.Index(.Items, 0, 6)))
Sheets("CLS").Cells(1, 7).Resize(, 6) = Array("DATE", "NAME", "BALANCES", "DEBIT", "CREDIT", "TOTAL")
Sheets("CLS").Cells(2, 7).Resize(.Count, 6) = Application.Index(.Items, 0, 0)
End With
End Sub
If this works for you, please remember to mark this Answer as Selected.