楼上的答案可以说是对的,但如果要排序,最好是使用自定义函数不完成。
自定义函数代码如下:
Function SortIf(ByVal rg1 As Range, ByVal rg2 As Range)
Dim rg As Range, rng As Range, i%, k%, s%, n%, arr()
Set rg = Range(rg1, rg2)
For Each rng In rg
For i = 1 To Len(rng)
s = Mid(rng, i, 1)
On Error GoTo l
For j = 0 To UBound(arr())
If s = arr(j) Then GoTo ll
Next
l:
ReDim Preserve arr(k)
arr(k) = s
k = k + 1
ll:
Next
Next
For i = 0 To UBound(arr()) - 1
m = i
For j = i + 1 To UBound(arr())
If arr(j) > arr(m) Then
m = j
End If
Next
If m <> i Then
n = arr(i)
arr(i) = arr(m)
arr(m) = n
End If
Next
For i = 0 To UBound(arr())
SortIf = SortIf & arr(i)
Next
End Function