| ©«¤l5923 ¥DÃD13 ºëµØ1 ¿n¤À5986 ÂI¦W0  §@·~¨t²Îwin10 ³nÅ骩¥»Office 2010 ¾\ŪÅv150 ©Ê§O¨k ¨Ó¦Û¥xÆW°ò¶© µù¥U®É¶¡2010-5-1 ³Ì«áµn¿ý2022-1-23 
         
 | 
                
| ¦^´_ 1# cdcc ½Æ»s¥N½XSub Ex1()
    Dim i%, Rng As Range
    With Sheet1
         '1 ¿z¿ï
         Range("A4").Sort Key1:=Range("E5"), Order1:=xlAscending, Key2:=Range("A5"), Order2:=xlAscending, Header:=xlYes
        i = 5
        Do While .Cells(i, "A").End(xlDown).Row <> Rows.Count
            If .Cells(i, "A") & .Cells(i, "A") <> "" And .Cells(i + 1, "A") & .Cells(i + 1, "A") <> "" Then
                If .Cells(i, "A") & .Cells(i, "A") <> .Cells(i + 1, "A") & .Cells(i + 1, "A") Then
                    i = i + 1
                    Set Rng = .Range(.Cells(i, "A"), .Cells(Rows.Count, "G").End(xlUp))
                    '2 ²¾°Ê½d³ò
                    Rng.Cut Rng.Offset(2)
                    i = i + 1
                End If
            End If
            i = i + 1
        Loop
        Set Rng = .Range("G5", .Cells(Rows.Count, "G").End(xlUp))
        For Each E In Rng.SpecialCells(xlCellTypeConstants).Areas
            E(E.Count + 1, 0).Value = "Sub Total:"
            '3 µ¹È
            With E(E.Count + 1)
                .Value = Application.Sum(E)
                .Borders(3).LineStyle = 1
                .Borders(3).Weight = 2
                .Borders(4).LineStyle = 1
                .Borders(4).Weight = 3
            End With
        Next
    End With
    Set Rng = Nothing
End Sub
½Æ»s¥N½XSub Ex2()   '°}¦C¤è¦¡
    Dim D As Object, Rng As Range, R, AR
    Set D = CreateObject("Scripting.dictionary")
    With Sheet1
         Range("A4").Sort Key1:=Range("E5"), Order1:=xlAscending, Key2:=Range("A5"), Order2:=xlAscending, Header:=xlYes
        Set Rng = .Range(.[a5], .[a5].End(xlToRight).End(xlDown))
    End With
    For Each R In Rng.Rows
        If D.Exists(R.Cells(1, 1) & R.Cells(1, 5)) Then
            AR = D(R.Cells(1, 1) & R.Cells(1, 5))
            ReDim Preserve AR(1 To UBound(AR), 1 To UBound(AR, 2) + 1)
            For i = 1 To UBound(AR)
                AR(i, UBound(AR, 2)) = R.Cells(i)
            Next
            D(R.Cells(1, 1) & R.Cells(1, 5)) = AR
        Else
            D(R.Cells(1, 1) & R.Cells(1, 5)) = Application.Transpose(R.Value)
        End If
    Next
    With Sheet1
         .Range(.[a5], .Cells(Rows.Count, "G")).Clear
         Set Rng = .[a5]
    End With
    For Each R In D.KEYS
        Rng.Resize(UBound(D(R), 2), 7) = Application.Transpose(D(R))
        With Rng.Cells(UBound(D(R), 2) + 1, 5)
            .Value = "Sub Total:"
            With .Offset(, 1)
                .Value = Application.Sum(Application.Index(D(R), 6))
                .Borders(3).LineStyle = xlContinuous
                .Borders(3).Weight = xlThin
                .Borders(4).LineStyle = xlContinuous
                .Borders(4).Weight = 3
            End With
        End With
        Set Rng = Rng.Cells(1).Offset(UBound(D(R), 2) + 2)
     Next
    Set D = Nothing
    Set Rng = Nothing
End Sub
 | 
 |