返回列表 上一主題 發帖

請教資料依2欄排序

請教資料依2欄排序

有個排序問題麻煩幫忙~~
E欄14到16945開始排序從小到大,
D14到16945開始遇到E欄遇0為從小到大,遇到E欄為1則從大到小,遇到E欄為2則從小到大,
遇到E欄為3則從小到大,依此類推,而且其它例資料也需跟著移動,資料如附件。

CP2_t.rar (460.9 KB)

Simon

回復 2# Hsieh


    感謝你的幫忙,另外請教如果E欄有300筆,就需作300次,如果用VBA要如何寫,在下是用巨集跑,如何縮短程式(如下,只跑四筆資料),謝謝。

Sub Macro2()
'
' Macro2 Macro
' 11 在 2012/7/18 錄製的巨集
    Rows("13:13").Select
    Selection.AutoFilter
    Range("A13:AF16945").Sort Key1:=Range("E13"), Order1:=xlAscending, Header _
        :=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom _
        , SortMethod:=xlStroke, DataOption1:=xlSortNormal
    Selection.AutoFilter Field:=5, Criteria1:="0"
    Range("A13:AF16945").Sort Key1:=Range("D13"), Order1:=xlAscending, Header _
        :=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom _
        , SortMethod:=xlStroke, DataOption1:=xlSortNormal
    Selection.AutoFilter Field:=5, Criteria1:="1"
    Range("A13:AF16945").Sort Key1:=Range("D13"), Order1:=xlDescending, Header _
        :=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom _
        , SortMethod:=xlStroke, DataOption1:=xlSortNormal
    Selection.AutoFilter Field:=5, Criteria1:="2"
    Range("A13:AF16945").Sort Key1:=Range("D13"), Order1:=xlAscending, Header _
        :=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom _
        , SortMethod:=xlStroke, DataOption1:=xlSortNormal
    Selection.AutoFilter Field:=5, Criteria1:="3"
    Range("A13:AF16945").Sort Key1:=Range("D13"), Order1:=xlDescending, Header _
        :=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom _
        , SortMethod:=xlStroke, DataOption1:=xlSortNormal
    Selection.AutoFilter Field:=5, Criteria1:="4"
    Range("A13:AF16945").Sort Key1:=Range("D13"), Order1:=xlAscending, Header _
        :=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom _
        , SortMethod:=xlStroke, DataOption1:=xlSortNormal
    Selection.AutoFilter Field:=5
    Selection.AutoFilter
End Sub
Simon

TOP

回復 4# Hsieh


    感謝板主的指導,我再試試看,謝謝。
Simon

TOP

        靜思自在 : 不怕事多,只怕多事。
返回列表 上一主題