Guest User

Untitled

a guest
Jan 23rd, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. Sub nSum()
  2. Dim Rng As Range, Dn As Range, n As Long, Txt As String, Ac As Long
  3. Set Rng = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
  4. ray(1 To Rng.Count, 1 To 4) 'Column count ''***ERROR LINE***************
  5. With CreateObject("scripting.dictionary")
  6. .CompareMode = vbTextCompare
  7. For Each Dn In Rng
  8. Txt = Join(Application.Transpose(Application.Transpose(Dn.Resize(, 3))), ",")
  9. If Not .Exists(Txt) Then
  10. n = n + 1
  11. For Ac = 1 To 4: ray(n, Ac) = Dn.Offset(, Ac - 1): Next Ac
  12. .Add Txt, n
  13. Else
  14. ray(.Item(Txt), 4) = ray(.Item(Txt), 4) + Dn.Offset(, 3)
  15. End If
  16. Next
  17. n = .Count
  18. End With
  19. With Sheets("Sheet2").Range("A1").Resize(n, 4)
  20. .Value = ray
  21. .Borders.Weight = 2
  22. .Columns.AutoFit
  23. End With
  24. End Sub'
Add Comment
Please, Sign In to add comment