Advertisement
YasserKhalil2019

T3623_SUM Similar Items SUM Unique In Three Columns

Jul 15th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. https://excel-egy.com/forum/t3623
  2. ---------------------------------
  3.  
  4. Sub SUM_Similar_Items_SUM_Unique_In_Three_Columns_Dictionary()
  5. Dim a, ws As Worksheet, i As Long, ii As Long, txt As String
  6.  
  7. Set ws = ThisWorkbook.Worksheets("ITEMS")
  8. a = ws.ListObjects(1).DataBodyRange.Value
  9.  
  10. With CreateObject("Scripting.Dictionary")
  11. For i = 1 To UBound(a, 1)
  12. If a(i, 1) <> "" Then
  13. txt = Join(Array(a(i, 1), a(i, 2), a(i, 3)), Chr(2))
  14. If Not .Exists(txt) Then
  15. .Item(txt) = .Count + 1
  16. For ii = 1 To UBound(a, 2)
  17. a(.Count, ii) = a(i, ii)
  18. Next ii
  19. Else
  20. For ii = 4 To 7
  21. a(.Item(txt), ii) = a(.Item(txt), ii) + a(i, ii)
  22. Next ii
  23. End If
  24. End If
  25. Next i
  26. i = .Count
  27. End With
  28.  
  29. ws.ListObjects(1).DataBodyRange.ClearContents
  30. ws.Range("B2").Resize(i, UBound(a, 2)) = a
  31. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement