Advertisement
YasserKhalil2019

T3925_Unique In Three Columns SUM Total By Dictionary

Sep 16th, 2019
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. https://excel-egy.com/forum/t3925
  2. ---------------------------------
  3.  
  4. Sub Unique_In_Three_Columns_SUM_Total_By_Dictionary()
  5. Dim a, e, ws As Worksheet, sh As Worksheet, dic As Object, s As String, i As Long
  6.  
  7. Set ws = ThisWorkbook.Sheets(1)
  8. Set sh = ThisWorkbook.Sheets(2)
  9. Set dic = CreateObject("Scripting.Dictionary")
  10.  
  11. For Each e In Array(0, 1)
  12. If e = 0 Then
  13. a = ws.Range("B5:E" & ws.Cells(Rows.Count, "B").End(xlUp).Row).Value
  14. Else
  15. a = sh.Range("C4:F" & sh.Cells(Rows.Count, "C").End(xlUp).Row).Value
  16. End If
  17.  
  18. For i = LBound(a, 1) To UBound(a, 1)
  19. s = Trim(a(i, 1)) & vbTab & Trim(a(i, 2)) & vbTab & Trim(a(i, 3))
  20. If Not dic.Exists(s) Then dic(s) = Array(, , , 0)
  21. dic(s) = Array(Trim(a(i, 1)), Trim(a(i, 2)), Trim(a(i, 3)), dic(s)(3) + Val(a(i, 4)))
  22. Next i
  23. Next e
  24.  
  25. Application.ScreenUpdating = False
  26. With sh.Range("K4")
  27. .Resize(1, 4).Value = Array("الصنف", "النوع", "المنشأ", "الرصيد")
  28. .Offset(1).Resize(dic.Count, 4).Value = Application.Transpose(Application.Transpose(dic.items))
  29. End With
  30. Application.ScreenUpdating = True
  31. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement