- ©«¤l
- 1447
- ¥DÃD
- 40
- ºëµØ
- 0
- ¿n¤À
- 1471
- ÂI¦W
- 0
- §@·~¨t²Î
- Windows 7
- ³nÅ骩¥»
- Excel 2010 & 2016
- ¾\ŪÅv
- 50
- ©Ê§O
- ¨k
- ¨Ó¦Û
- ¥xÆW
- µù¥U®É¶¡
- 2020-7-15
- ³Ì«áµn¿ý
- 2024-12-5
|
¦^´_ 3# ã´£³¡ªL
ÁÂÁ«e½ú
«á¾ÇÂǦ¹©«¾Ç²ß«e½úªº¤è®×,¾Ç²ß¤ß±oµù¸Ñ¦p¤U,½Ð«e½ú¦A«ü¾É
Sub TEST_A1()
Dim Arr, Brr, Crr, i&, j%, N&, T$, D, DS, TD$, S1, S2
'¡ô«Å§iÅܼÆ
With Range(Sheet1.[d1], Sheet1.[a65536].End(3)(2))
'¡ô¦J¦CÀx¦s®æ½d³ò
Brr = .Value
'¡ô¥OÅܼƦ¨¬°°}¦C,¥HÀx¦s®æȱa¤J°}¦C
.Sort key1:=.Item(4), Order1:=xlAscending, key2:=.Item(1), Order2:=xlDescending, Header:=xlYes
'¡ô¥O¦J¦CÀx¦s®æ½d³ò°µ¨â¼h¦¸ªº¦³¼ÐÃD¦C±Æ§Ç
Arr = .Value
'¡ô¥O¥t¤@ÓÅܼƦ¨¬°°}¦C,¥H±Æ§Ç«áªºÀx¦s®æȱa¤J°}¦C
.Offset(1).ClearContents
'¡ô¥O¦J¦CÀx¦s®æ½d³ò
Crr = .Resize(UBound(Brr) * 3)
'¡ô¥OCrr¬O¦J¦C¼Ð´£¦C¦V¤U(3¿Brr°}¦CÁa¦V¦C¼Æ)ªº¤Gºû°}¦C
MsgBox "Crr°}¦CÁa¦V³Ì¤j¯Á¤Þ¸¹: " & UBound(Crr)
.Value = Brr
'¡ô¥OSheet1³Q¦J¦CÀx¦s®æ«ì´_ì¨ÓªºÀx¦s®æÈ
End With
For i = 2 To UBound(Arr) - 1
'¡ô³]¶¶°j°é
T = Arr(i, 1): D = Arr(i, 4)
'¡ô¥OÅܼƱa¤JÈ
If T & D <> TD Then TD = T & D: S1 = 0
'¡ô¦pªGTÅÜ¼Æ ³s±µDÅÜ¼Æ ²Õ¦¨ªº·s¦r¦ê »PTDÅܼƤ£¦P,
'´N¥OTDÅܼƬO TÅÜ¼Æ ³s±µDÅÜ¼Æ ²Õ¦¨ªº·s¦r¦ê,¥OS1ÅÜ¼Æ Âk¹s
If D <> DS Then DS = D: S1 = 0: S2 = 0
'¡ô¦pªGDÅÜ¼Æ »PDSÅܼƤ£¬Û¦P!´N¥O DSÅܼÆȦP DÅܼÆ,
'¥OS1ÅܼÆÂk¹s,¥OS2ÅܼƤ]Âk¹s
N = N + 1
'¡ô¥ONÅܼƲ֥[1
For j = 1 To 4: Crr(N + 1, j) = Arr(i, j): Next
'¡ô³]¶¶°j°é±NArr°}¦CȳvÄæ±a¤J«ü©wªºCrr°}¦C¦ì¸m
S1 = S1 + Arr(i, 3): S2 = S2 + Arr(i, 3)
'¡ô¥OS1ÅܼƲ֥[ ¦P½s¸¹ªºª÷ÃB
'¡ô¥OS2ÅܼƲ֥[ ¦P¤é´Áªºª÷ÃB
If Arr(i + 1, 1) & Arr(i + 1, 4) = TD Then GoTo i01
'¡ô¦pªG½s¸¹³s±µ¤é´Á²Õ¦¨ªº·s¦r¦ê»P TDÅܼƬۦP!´N¸õ¨ì i01¦ì¸mÄ~Äò°õ¦æ
N = N + 1: Crr(N + 1, 2) = "<SUM>": Crr(N + 1, 3) = S1
'¡ô¥OªÅ¥X¤@¦C±a¤J"<SUM>"¼Ð°O»P ¤ppÈ
If Arr(i + 1, 4) <> DS Then N = N + 2: Crr(N, 2) = "<TOTLA>": Crr(N, 3) = S2
'¡ô¦pªG¤é´Á»PDSÅܼƤ£¦P!´NªÅ¥X 2¦C,±a¤J"<TOTLA>"¼Ð°O»P ¤é´ÁÁ`pÈ
i01: Next i
With Sheet2
.UsedRange.ClearContents
'¡ô¥O²M°£ªí2 ¸ê®Æ
.[a1].Resize(N + 1, 4) = Crr
'¡ô¥OCrr°}¦Cȼg¤Jªí2
End With
End Sub |
|