恩,这个问题有搞头,是需要一定技巧的
这是我的代码供参考(只需一个循环)
Dim i&, p&, n&, m1&, m2&
Dim arr, arr1, arr2, arr3()
Application.ScreenUpdating = False
p = [a65536].End(xlUp).Row
ReDim arr3(1 To p - 1, 1 To 3)
arr = Range(Cells(2, 1), Cells(p, 3))
Range(Cells(2, 1), Cells(p, 3)).Sort Key1:=Range("C2"), Order1:=xlAscending, Key2:=Range("A2"), Order2:=xlAscending, Header:=xlGuess
arr1 = Range(Cells(2, 1), Cells(p, 3))
Range(Cells(2, 1), Cells(p, 3)).Sort Key1:=Range("C2"), Order1:=xlAscending, Key2:=Range("B2"), Order2:=xlAscending, Header:=xlGuess
arr2 = Range(Cells(2, 1), Cells(p, 3))
n = 1: m1 = 1: m2 = 1
For i = 2 To p - 1
If arr1(i, 3) <> arr1(i - 1, 3) Then
arr3(n, 1) = arr1(i - 1, 3)
arr3(n, 2) = m1
arr3(n, 3) = m2
n = n + 1: m1 = 1: m2 = 1
Else
If arr1(i, 1) <> arr1(i - 1, 1) Then m1 = m1 + 1
If arr2(i, 2) <> arr2(i - 1, 2) Then m2 = m2 + 1
End If
Next i
arr3(n, 1) = arr1(p - 1, 3): arr3(n, 2) = m1: arr3(n, 3) = m2
Range("e2:g" & p) = arr3
Range(Cells(2, 1), Cells(p, 3)) = arr
VmHbDz6W.rar
(9.65 KB, 下载次数: 60)
严谨起见,又修改了一下
[此贴子已经被作者于2005-9-28 17:20:25编辑过] |