经过本人亲自测试,对Excel进行排序,如果用到一般的排序,如冒泡排序,这里效率非常低,即使经过反复优化的话,效率也难达到秒杀地步。(比如 Rows.Count 达到e4的数量级时),如果直接使用VBA那就能实现高效排序:
升序:
Sub MacroPinyin_Ascend() ' ' Macro1 Macro ' 宏由 Chenwb 录制,时间: 2013-9-22 ' '表1 双字节区的21003汉字 '按照GB8030编码增序排列 Dim lRow As Long Dim lCol As Long Dim myRng As Range With Worksheets("Sheet1") lRow = Cells(Rows.Count, 1).End(xlUp).Row lCol = Cells(1, "G").Column Set myRng = .Range(Cells(1, 1), Cells(lRow, lCol)) myRng.Sort _ Key1:=.Range("A1"), _ Order1:=xlAscending, _ Header:=xlYes, _ Orientation:=xlTopToBottom End With ' End Sub
降序:
Sub MacroPinyin_Descend() ' ' Macro2 Macro ' 宏由 Chenwb 录制,时间: 2013-9-22 ' '表1 双字节区的21003汉字 '按照GB8030编码减序排列 Dim lRow As Long Dim lCol As Long Dim myRng As Range With Worksheets("Sheet1") lRow = Cells(Rows.Count, 1).End(xlUp).Row lCol = Cells(1, "G").Column Set myRng = .Range(Cells(1, 1), Cells(lRow, lCol)) myRng.Sort _ Key1:=.Range("A1"), _ Order1:=xlDescending, _ Header:=xlYes, _ Orientation:=xlTopToBottom End With ' End Sub