字符串数组排序函数(JScript法)来源:excel格子社区今天在EH中,发现一个利用JScript排序字符串数组的方法,便把它摘录如下: FunctionSortArr(ArrAsVariant,OptionalsPdAsBoolean=True)'' ''时间:2010-3-22''出外:http: //club.excelhome.net/thread-389688-1-1.html''作者:LDY''功能:给指定的数据排序''说明 :sPd参数,True为顺序,False为倒序。''?????其中中文为按笔划排序。''整理:http://www.excelba. com''DimsAsStringSta ticsp1AsObjectIfsPdThens="functionsortarr(arr){return(ar r.toArray().sort());}"???''顺序Elses="functionsortarr(arr){retu rn(arr.toArray().sort().reverse());}"''倒序EndIfIfsp1IsNothing ThenSetsp1=CreateObject("ScriptControl")sp1.Language="JScr ipt"EndIfsp1.AddCodesSortArr=sp1.Run("sortarr",Arr)EndFunct ion这个函数可以排序指定的数组,下面说一个应用,如把Excel当前工作表中A列的数据,按顺序加入窗体中的复合框中(PS:复合框名 称为ComboBox1)PrivateSubUserForm_Initialize()ComboBox1.List=Spl it(SortArr(Range("A1:A"&Range("A"&Cells.Rows.Count).End(xlUp) .Row).Value,False),",")EndSub感觉挺快的,也挺有用的,就在此与大家分享。1格子社区-Exce l互助交流平台 |
|