'应该差不多,自己测试一下
Option Explicit
Sub test()
Dim arr, dic, pos, i, j, k, a, mark, m, n, sht, key, max
Set dic = CreateObject("scripting.dictionary")
mark = "一二三"
arr = Sheets("sheet2").[a1].CurrentRegion
ReDim brr(1 To 10 ^ 3, 1 To UBound(arr, 1), 1 To 3)
ReDim pos(1 To 10 ^ 3, 1 To 3), max(1 To UBound(arr, 1))
For i = 2 To UBound(arr, 1)
a = Val(InStr(mark, Left(arr(i, 2), 1)))
If dic.exists(arr(i, 3)) Then
pos(dic(arr(i, 3)), a) = pos(dic(arr(i, 3)), a) + 1
brr(dic(arr(i, 3)), pos(dic(arr(i, 3)), a), a) = arr(i, 1)
If max(dic(arr(i, 3))) < pos(dic(arr(i, 3)), a) Then _
max(dic(arr(i, 3))) = pos(dic(arr(i, 3)), a)
Else
m = m + 1: dic(arr(i, 3)) = m
pos(m, a) = pos(m, a) + 1: max(m) = pos(m, a)
brr(m, pos(m, a), a) = arr(i, 1)
End If
Next
For Each key In dic.keys
i = 0
For Each sht In Sheets
If key = sht.Name Then i = 1: Exit For
Next
If i = 0 Then
Sheets.Add
With ActiveSheet
.Name = key
.[a1].Resize(, 3) = Split("一星会员 二星会员 三星会员")
End With
Else
Sheets(key).[a2].Resize(Rows.Count - 1, 3).ClearContents
End If
ReDim arr(1 To max(dic(key)), 1 To 3)
For i = 1 To UBound(arr, 1)
For j = 1 To UBound(arr, 2)
arr(i, j) = brr(dic(key), i, j)
Next j, i
Sheets(key).[a2].Resize(UBound(arr, 1), UBound(arr, 2)) = arr
Next
End Sub |