テーブルに入れると言う手もあります
これが一番簡単
SQLserverとつながっているなら一時テーブルに入れ込む
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
Public Function TableSort(Ary As Variant) As Variant 'Dim Ary 'Ary = Array("5", "4", "1", "2", "900", "888") Dim cn As ADODB.Connection Dim rs As ADODB.Recordset Set cn = New ADODB.Connection Set rs = New ADODB.Recordset cn.ConnectionString = "接続文字列" cn.Open Dim I As Long I = 0 cn.Execute "drop table if exists #AryT" cn.Execute "select " & CLng(Ary(I)) & "as C into #AryT" For I = 1 To UBound(Ary) cn.Execute "insert into #AryT(C) values(" & CLng(Ary(I)) & ")" Next I rs.Open "select C from #AryT order by C asc", cn, adOpenStatic, adLockOptimistic rs.MoveFirst I = 0 Do Until rs.EOF Ary(I) = rs!C rs.MoveNext I = I + 1 Loop 'For I = 0 To UBound(Ary) ' Debug.Print Ary(I) 'Next TableSort = Ary rs.Close cn.Close End Function |