Hello Gurus:
Please help me add a sorting code to the original code so that the new code will sort "Quote Summary" sheet according to column C in Descending Order after the execution of the original code.
The attached spreadsheet has been processed by the original code.
Quote History-Process Sample v.2-Part c.xlsm
Original Code:
Sub QuoteSummary():
Dim ws As Worksheet, wq As Worksheet, Headers As String, PNo As String, P As Range, i As Long, j As Long, s As Long, PSm As Single: s = 2
Headers = _
("Part Number,Part Description,Total Quoted Value,Annually Average Quoted Value")
Set wq = Sheets("Quote History")
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Quote Summary"
Set ws = Sheets("Quote Summary")
ws.Range("A1").Resize(1, 4).Value = Split(Headers, ","): ws.Columns.AutoFit
ws.Columns("C:D").NumberFormat = "$0.00": wq.Activate
wq.UsedRange.Sort Key1:=Range("D1"), Header:=xlYes
For i = 2 To wq.Range("D" & Rows.Count).End(xlUp).Row - 1
PNo = Range("D" & i)
For j = i + 1 To wq.Range("D" & Rows.Count).End(xlUp).Row
If wq.Range("D" & j) <> PNo Then
Set P = wq.Range("P" & i & ":P" & j - 1): PSm = WorksheetFunction.Sum(P)
ws.Range("C" & s) = PSm: ws.Range("D" & s) = PSm / 4
ws.Range("A" & s) = wq.Range("D" & i): ws.Range("B" & s) = wq.Range("E" & i)
s = s + 1: i = j - 1: GoTo GetNext: End If: Next j
GetNext: Next i: ws.Columns.AutoFit: ws.Activate
End Sub
Any input is appreciated,
Chris
Bookmarks