ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] VBA sum °ÝÃD

¦^´_ 1# john2006168


    ¼Ï¯Ã¤ÀªRªí³Ì§Ö
­Y¯Âºé°Q½×VBA
  1. Sub Ex()
  2. Set d = CreateObject("Scripting.Dictionary")
  3. d("ref no") = Array("ref no", "Sum of ctr", "Sum of gw", "remark")
  4. With Sheet1
  5. For Each a In .Range(.[A2], .[A65536].End(xlUp))
  6.   If Not d.exists(a & a.Offset(, 3)) Then
  7.      d(a & a.Offset(, 3)) = Array(a.Value, a.Offset(, 1).Value, a.Offset(, 2).Value, a.Offset(, 3).Value)
  8.      Else
  9.      ar = d(a & a.Offset(, 3))
  10.      ar(1) = ar(1) + a.Offset(, 1): ar(2) = ar(2) + a.Offset(, 2)
  11.      d(a & a.Offset(, 3)) = ar
  12.   End If
  13. Next
  14. End With
  15. Sheet2.Columns("A:D") = ""
  16. Sheet2.[A1].Resize(d.Count, 4) = Application.Transpose(Application.Transpose(d.items))
  17. End Sub
½Æ»s¥N½X
¼Ï¯Ã.zip (11.75 KB)
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¦^´_ 4# john2006168


If Not d.exists(a & a.Offset(, 3)) Then'°²¦p¦r¨åª«¥ó§ä¤£¨ìa & a.Offset(, 3)´N¬Od.(a & a.Offset(, 3)) ÁÙ¨S«Ø¥ß®É

d(a & a.Offset(, 3)) = Array(a.Value, a.Offset(, 1).Value, a.Offset(, 2).Value, a.Offset(, 3).Value)'´N½á¤©d.(a & a.Offset(, 3)) ªº¤º®e¬°¤@°}¦C

Else'§_«h

ar = d(a & a.Offset(, 3))'¨ú¥Xd.(a & a.Offset(, 3))

ar(1) = ar(1) + a.Offset(, 1): ar(2) = ar(2) + a.Offset(, 2)'§ïÅܨú¥Xªº°}¦C¤¸¯À­È

d(a & a.Offset(, 3)) = ar'¦s¦^§ïÅܫ᪺°}¦Cµ¹d.(a & a.Offset(, 3))
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

        ÀR«ä¦Û¦b : ¤£©È¨Æ¦h¡A¥u©È¦h¨Æ¡C
ªð¦^¦Cªí ¤W¤@¥DÃD