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

[µo°Ý] §âÂø¶ÃµL³¹ªº¸ê®Æ¡A¾ã²z¦¨¨C­Ó½s¸¹ªº²Õ¦X

[µo°Ý] §âÂø¶ÃµL³¹ªº¸ê®Æ¡A¾ã²z¦¨¨C­Ó½s¸¹ªº²Õ¦X

§â Sheet1 Âø¶ÃµL³¹ªº¸ê®Æ¡A¾ã²z¦¨¦¹ªí¤¤¥H¨C­Ó½s¸¹¬°¤@²Õ¨Ã¥B¤p­pª÷ÃB¡A­pºâÁ`ÃB¡F

½s¸¹¬O¥Ñ¤j¦Ü¤p±Æ¦C¡A¤é´Á¥H³Ì¦­¨ì³Ìªñ±Æ¦C¡A½Ð°ÝVBA¦p¦ó¹ê²{¡H

ÁÂÁ¦U¦ì°ª¤â½ç±Ð¡I




RA.rar (10.06 KB)

¥i¥H¥ÎSQL°µ¨ì´N³Ì¦n¤F

TOP

VBA..»PEH¦P¤@ªþ¥ó//
Xl0000166.rar (17.44 KB)

TOP

¦^´_ 1# maiko


    ÁÂÁ«e½úµoªí¦¹¥DÃD»P½d¨Ò
«á¾ÇÂǦ¹©«¾Ç²ß¥HVBA°õ¦æ¤p­p¥\¯à,¾Ç²ß¤è®×¦p¤U,½Ð«e½ú°Ñ¦Ò

°õ¦æµ²ªG:


Option Explicit
Sub TEST()
Application.ScreenUpdating = False: Sheet1.[A:D].Copy [Sheet2!A1]
With [Sheet2!A1].CurrentRegion
   .Sort KEY1:=.Item(4), Order1:=1, Key2:=.Item(1), Order2:=2, Header:=1, Orientation:=1
   .Subtotal GroupBy:=4, Function:=xlSum, TotalList:=Array(3), SummaryBelowData:=True
End With
With Sheet2.[A1].CurrentRegion
   .Value = .Value
   .Subtotal GroupBy:=2, Function:=xlSum, TotalList:=Array(3), SummaryBelowData:=True
End With
With Sheet2.[A1].CurrentRegion
   .Cells.ClearOutline: .Offset(.EntireRow.Rows.Count - 2).Clear: .EntireColumn.AutoFit
End With
End Sub
¥Î¦æ°Ê¸Ë¸mÂsÄý½×¾Â¾Ç²ß«Ü¤è«K,ÁÂÁ½׾¸gÀç¹Î¶¤
½Ð¤j®a¤@°_¤W½×¾Â¨Ó¥æ¬y

TOP

¦^´_ 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 ¤p­p­È
    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
¥Î¦æ°Ê¸Ë¸mÂsÄý½×¾Â¾Ç²ß«Ü¤è«K,ÁÂÁ½׾¸gÀç¹Î¶¤
½Ð¤j®a¤@°_¤W½×¾Â¨Ó¥æ¬y

TOP

ÁÂÁ¦U¦ì±Ð¾É

TOP

        ÀR«ä¦Û¦b : ¤f»¡¦n¸Ü¡B¤ß·Q¦n·N¡B¨­¦æ¦n¨Æ¡C
ªð¦^¦Cªí ¤W¤@¥DÃD