Advertisement
YasserKhalil2019

T3705_Account Statement Unique Totals Arrays Dictionary

Jul 30th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. https://excel-egy.com/forum/t3705
  2. ---------------------------------
  3.  
  4. Sub Account_Statement_Unique_Totals_Arrays_Dictionary()
  5. Dim ws As Worksheet
  6. Dim sh As Worksheet
  7. Dim dic As Object
  8. Dim a As Variant
  9. Dim b As Variant
  10. Dim s As String
  11. Dim i As Long
  12. Dim j As Long
  13. Dim k As Long
  14.  
  15. Application.ScreenUpdating = False
  16. Set ws = ThisWorkbook.Worksheets("Data")
  17. Set sh = ThisWorkbook.Worksheets("Report")
  18. Set dic = CreateObject("Scripting.Dictionary")
  19. a = ws.Range("B3").CurrentRegion.Value
  20. ReDim b(1 To UBound(a), 1 To 6)
  21.  
  22. For i = 2 To UBound(a)
  23. If a(i, 5) = IIf(sh.Range("F2").Value = "", a(i, 5), sh.Range("F2").Value) Then
  24. s = a(i, 1) & Chr(2) & a(i, 5)
  25. If Not dic.Exists(s) Then
  26. k = k + 1
  27. dic.Add s, k
  28. For j = 1 To 5
  29. b(k, j) = a(i, j)
  30. Next j
  31. b(k, 6) = a(i, 7)
  32. Else
  33. b(dic(s), 6) = b(dic(s), 6) + a(i, 7)
  34. End If
  35. End If
  36. Next i
  37.  
  38. sh.Range("B4").CurrentRegion.Offset(1).ClearContents
  39. sh.Range("B5").Resize(k, UBound(b, 2)).Value = b
  40. Application.ScreenUpdating = True
  41. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement