Sub 数值降序()
Set js = CreateObject("msscriptcontrol.scriptcontrol")
js.Language = "javascript"
arr = Application.Transpose(Range("A1:A10"))
temp = Join(arr, ",")
js.addcode "function aa(bb){js=bb.split(',');js.sort(function(a,b){return a-b;});js.reverse();return js;}"
sortarr = js.eval_r("aa('" & temp & "')")
Debug.Print sortarr
End Sub
.NET里面有SortedList类也可以用来实现排序,但需要系统支持Framework
Sub Sortlist()
Set objSortedlist = CreateObject("System.Collections.Sortedlist")
For i = 1 To 10
objSortedlist.Add Range("A" & i).Value, Range("A" & i).Value
Next i
For i = 0 To objSortedlist.Count - 1
Debug.Print objSortedlist.GetKey(i)
Next
End Sub
除了SortedList类,还有ArrayList也可以用
Sub Arraylist()
Set objArrayList = CreateObject("System.Collections.ArrayList")
For i = 1 To 10
objArrayList.Add Range("A" & i).Value
Next i
objArrayList.Sort
For i = 0 To objArrayList.Count - 1
Debug.Print objArrayList(i)
Next
End Sub
还有其他什么好方法,欢迎大家支招。
|