|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
原帖由 yanjinwu 于 2010-11-12 10:35 发表
有没有大哥大姐们帮忙呀
呵呵,大姐帮忙了 - Sub MySort()
- Dim i&, k&, Arr, MyStrA$
- Application.ScreenUpdating = False
- Application.Calculation = xlManual
- k = Range("k65536").End(3).Row
- Arr = Range("k1:k" & k)
- ReDim Preserve Arr(1 To k, 1 To 2)
- For i = 1 To UBound(Arr)
- MyStrA = Arr(i, 1)
- If InStr(1, MyStrA, "左") Then
- Arr(i, 1) = Replace(Arr(i, 1), "左", "")
- Arr(i, 2) = "左"
- ElseIf InStr(1, MyStrA, "右") Then
- Arr(i, 1) = Replace(Arr(i, 1), "右", "")
- Arr(i, 2) = "右"
- End If
- Next i
- Arr(1, 1) = "排序字段一"
- Arr(1, 2) = "排序字段二"
- [X1].Resize(k, 2) = Arr
- ActiveWorkbook.Worksheets("Sheet1 (2)").Sort.SortFields.Clear
- ActiveWorkbook.Worksheets("Sheet1 (2)").Sort.SortFields.Add Key:=Range( _
- "X2:X" & k), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
- xlSortNormal
- ActiveWorkbook.Worksheets("Sheet1 (2)").Sort.SortFields.Add Key:=Range( _
- "Y2:Y" & k), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
- xlSortNormal
- With ActiveWorkbook.Worksheets("Sheet1 (2)").Sort
- .SetRange Range("A1:Y" & k)
- .Header = xlYes
- .MatchCase = False
- .Orientation = xlTopToBottom
- .SortMethod = xlPinYin
- .Apply
- End With
- Application.Calculation = xlCalculationAutomatic
- Application.ScreenUpdating = True
- MsgBox ("搞好了!")
- End Sub
复制代码 |
|