Option Explicit Sub abc() Dim a, i, j, k, p, m a = [a1].CurrentRegion.Offset(1).Value Call qsort(a, 1, UBound(a) - 1, 1, UBound(a, 2), 6) '第6列部门 For i = 1 To UBound(a) - 1 If a(i, 6) <> a(i + 1, 6) Then Call qsort(a, p + 1, i, 1, UBound(a, 2), 7) '第7列销量,自己修改 For j = p + 1 To p + Round((i - p) * 0.1, 0) m = m + 1 For k = 1 To UBound(a, 2) a(m, k) = a(j, k) Next Next p = i End If Next [a2].Offset(, UBound(a, 2) + 1).Resize(m, UBound(a, 2)) = a End Sub Function qsort(a, first, last, left, right, key) Dim i As Long, j As Long, k As Long, x, t i = first: j = last: x = a((first + last) \ 2, key) While i <= j While a(i, key) > x: i = i + 1: Wend While x > a(j, key): j = j - 1: Wend If i <= j Then For k = left To right t = a(i, k): a(i, k) = a(j, k): a(j, k) = t Next i = i + 1: j = j - 1 End If Wend If first < j Then qsort a, first, j, left, right, key If i < last Then qsort a, i, last, left, right, key End Function