以下是引用山菊花在2008-2-4 18:49:44的发言:
Public ds Sub 整理() On Error Resume Next Dim ary(), arr As Range, c As Range, c2 As Range, cAddress$ Application.EnableEvents = False If TypeName(ds) = "Empty" Then Dim nRow%, m% Set ds = CreateObject("scripting.dictionary") '定义字典 nRow = Sheets("笔画库").[a65536].End(xlUp).Row hanzi = Sheets("笔画库").Range("a1:a" & nRow) For i = 1 To nRow '把汉字添加到字典中 ds.Add hanzi(i, 1), m + 1 If Err.Number = 0 Then m = m + 1 End If Err.Clear Next End If cAddress = Selection.Address Set arr = Application.InputBox(Prompt:="说明:" & vbCrLf & vbNewLine & "所选区域将依照姓名笔划顺序按原布局重新调整。", Title:="选择要排序的区域 ... ...", Type:=8, Default:=cAddress) Application.ScreenUpdating = False If arr Is Nothing Then: Exit Sub p = Application.WorksheetFunction.CountA(arr) ReDim ary(1 To p, 1 To 2) For Each c2 In arr If c2 <> "" Then k = k + 1 ary(k, 1) = c2 For m = 1 To Len(c2) If m > 4 Or Mid(c2, m, 1) = "(" Then Exit For ary(k, 2) = ary(k, 2) + ds(Mid(c2, m, 1)) * 10000 ^ (4 - m) Next End If Next Range("iu1:iv" & p) = ary Columns("IU:IV").Sort Key1:=Range("IV1"), Order1:=xlAscending, Header:=xlGuess, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod _ :=xlStroke, DataOption1:=xlSortNormal k = 0 For i = 1 To arr.Rows.Count For j = 1 To arr.Columns.Count If arr(i, j) <> "" Then: k = k + 1: arr(i, j) = Range("iu" & k) Next j Next i Range("iu1:iv" & k).ClearContents Application.EnableEvents = True Application.ScreenUpdating = True End Sub
学习了,很多方面知识的综合运用阿! |