|
我说一下我的思路
Sub 分类排序()
Range("E3:F" & Rows.Count) = ""
Dim ARR, ARR1(), ARR2(), BM, CS
A = Cells(Rows.Count, "A").End(3).Row
ARR = Range("A3:B" & A)
A = UBound(ARR)
For B = 1 To A
BM = ARR(B, 1)
CS = ARR(B, 2)
If Len(BM) = 3 Then
C = C + 1
D = 0
ReDim Preserve ARR1(1 To 3, 1 To C)
ARR1(1, C) = BM
ARR1(2, C) = CS
Else
D = D + 1
If D = 1 Then
ReDim ARR2(1 To 2, 1 To 1)
Else
ARR2 = ARR1(3, C)
End If
ReDim Preserve ARR2(1 To 2, 1 To D)
ARR2(1, D) = BM
ARR2(2, D) = CS
ARR1(3, C) = ARR2
End If
Next B
For A = UBound(ARR1, 2) - 1 To 1 Step -1
For B = 1 To A
If ARR1(2, B) < ARR1(2, B + 1) Then
For C = 1 To 3
GDZ = ARR1(C, B)
ARR1(C, B) = ARR1(C, B + 1)
ARR1(C, B + 1) = GDZ
Next C
End If
Next B
Next A
For A = 1 To UBound(ARR1, 2)
B = Cells(Rows.Count, "E").End(3).Row + 1
Cells(B, "E") = ARR1(1, A)
Cells(B, "F") = ARR1(2, A)
ARR2 = ARR1(3, A)
For C = UBound(ARR2, 2) - 1 To 1 Step -1
For D = 1 To C
If ARR2(2, D) < ARR2(2, D + 1) Then
GDZ1 = ARR2(1, D)
GDZ2 = ARR2(2, D)
ARR2(1, D) = ARR2(1, D + 1)
ARR2(2, D) = ARR2(2, D + 1)
ARR2(1, D + 1) = GDZ1
ARR2(2, D + 1) = GDZ2
End If
Next D
Next C
B = Cells(Rows.Count, "E").End(3).Row + 1
Cells(B, "E").Resize(UBound(ARR2, 2), 2) = WorksheetFunction.Transpose(ARR2)
Next A
End Sub
1、红色部分建立数组ARR1(1 To 3, 1 To C),把字节为3的编号和次数写入ARR1(1 ,C)和ARR1(2,C),同时把对应的字节为5的内容写进ARR2,并数组镶套数组ARR1(3,C)=ARR2
2、蓝色部分用排序法根据次数从大到小排序ARR1
3、红紫色部分把ARR1内容写入工作表,其中绿色部分用排序法根据次数从大到小排序ARR2并写入工作表
|
|