EXCEL自定义排序最多只能有255个值,超过了就不能用自定义序列了,使用以下方法
求助excelhome论坛得出的答案
Sub 自定义排序()
Application.ScreenUpdating = False
'排序标准
Dim d As Object
Set d = CreateObject("Scripting.Dictionary")
Dim rng, i%
rng = Sheets("查补排序").[a1].CurrentRegion
For i = 2 To UBound(rng) '不含标题
d(rng(i, 1)) = i '序号
Next
'数据源
Dim arr, brr
arr = [a1].CurrentRegion
ReDim brr(1 To UBound(arr, 2))
For i = 5 To UBound(arr, 2) '不含标题
If d.Exists(arr(1, i)) Then
brr(i) = d(arr(1, i)) '序号
Else
brr(i) = "不存在"
End If
Next
Set d = Nothing
Rows(1).Insert
[a1].Resize(1, UBound(brr)) = brr
[e1].Resize(UBound(arr) + 1, UBound(arr, 2)).Sort key1:=[e1], Orientation:=xlLeftToRight, order1:=xlAscending '按行排序,降序
Rows(1).Delete
Application.ScreenUpdating = True
MsgBox "排序完成"
End Sub