0

我有一个脚本:

Sub wsPOT()
    Dim wsPOT As Worksheet
    Dim cel As Range
    Dim lastrow As Long, lastrow2 As Long, fstcell As Long, i As Long, Er As Long, lstCol As Long, lstRow As Long

    Set wsPOT = Sheets("PO Tracking")

    With wsPOT
        wsPOT.Range("Q1:U1").Copy
        lastrow = wsPOT.Cells(Rows.Count, "B").End(xlUp).Row
            wsPOT.Range("V1:X1").Copy wsPOT.Range("H3:J" & lastrow)
            wsPOT.Range("N2:O2").Copy wsPOT.Range("N3:O" & lastrow)
            wsPOT.Range("P1:V1").Copy
            wsPOT.Range("B3:H" & lastrow).PasteSpecial xlPasteFormats
            wsPOT.Range("K3:K" & lastrow).Borders.Weight = xlThin


        lastrow = wsPOT.Cells(Rows.Count, "B").End(xlUp).Row
            wsPOT.Range("H:J").Calculate
            wsPOT.Range("B3:K" & lastrow).Sort key1:=Range("H3:H" & lastrow), order1:=xlAscending
        lastrow2 = wsPOT.Cells(Rows.Count, "H").End(xlUp).Row
            wsPOT.Range("B3:K" & lastrow2).Sort key1:=Range("H3:H" & lastrow2), order1:=xlDescending
    End With

End Sub

这是为了最终组织工作表,使迟到的工作排在最前面,然后按从大到小排列。

它似乎不起作用。似乎发生的是第一个组织工作正常,但它似乎忽略了第二个标准。

附件是表格,带有脚本。

https://dl.dropbox.com/u/3327208/Excel/Orga.xlsm

如果有人可以帮助看看这个,它会受到赞赏。

4

1 回答 1

2

这是你正在尝试的吗?

Option Explicit

Sub wsPOT()
    Dim wsPOT As Worksheet
    Dim cel As Range
    Dim lastrow As Long, lastrow2 As Long, fstcell As Long
    Dim i As Long, Er As Long, lstCol As Long, lstRow As Long

    Set wsPOT = Sheets("PO Tracking")

    With wsPOT
        .Range("Q1:U1").Copy
        lastrow = .Cells(.Rows.Count, "B").End(xlUp).Row
        .Range("V1:X1").Copy .Range("H3:J" & lastrow)
        .Range("N2:O2").Copy .Range("N3:O" & lastrow)
        .Range("P1:V1").Copy
        .Range("B3:H" & lastrow).PasteSpecial xlPasteFormats
        .Range("K3:K" & lastrow).Borders.Weight = xlThin
        lastrow = .Cells(.Rows.Count, "H").End(xlUp).Row
        .Range("H:J").Calculate

        .Sort.SortFields.Clear

        '~~> Sort on Red Icon First, putting it on top
        .Sort.SortFields.Add(.Range("J3:J" & lastrow), _
        xlSortOnIcon, xlAscending, , xlSortNormal).SetIcon Icon:=ActiveWorkbook. _
        IconSets(4).Item(1)

        '~~> Sort on Values of Red icon in descending order
        .Sort.SortFields.Add Key:=Range( _
        "J3:J" & lastrow), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
        xlSortNormal

        '~~> Sort on Green Icon Next, putting it on top after Red
        .Sort.SortFields.Add(.Range("I3:I" & lastrow), _
        xlSortOnIcon, xlAscending, , xlSortNormal).SetIcon Icon:=ActiveWorkbook. _
        IconSets(4).Item(3)

        '~~> Sort on Values of Green icon next in descending order
        .Sort.SortFields.Add Key:=Range( _
        "I3:I" & lastrow), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
        xlSortNormal

        With .Sort
            .SetRange wsPOT.Range("B2:K" & lastrow)
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    End With
End Sub
于 2012-08-28T14:17:10.963 回答