Article ID: 152383
Article Last Modified on 10/10/2006
A1: Stock Name B1: Yesterday's Quote C1: Today's Quote D1: Change A2: ABC B2: 2.00 C2: 3.00 D2: A3: LMO B3: 1.00 C3: 0.50 D3: A4: UVW B4: 5.00 C4: 9.00 D4: A5: XYZ B5: 12.00 C5: 11.50 D5:
D2: =C2-B2
D1: Change
D2: 1.00
D3: -0.50
D4: 4.00
D5: -0.50
Sub ActivateSortRoutine()
Workbooks("book1").Sheets("sheet1").OnCalculate = "SortRoutine"
' This sets the OnCalculate property. Replace book1 with your
' workbook including the file extension, if any, and sheet1 with
' the name of your sheet.
End Sub
Sub SortRoutine()
Range(ActiveCell.Address).CurrentRegion.Select ' Selects list.
Selection.Sort Key1:=Range("d2"), Order1:=xlDescending, Header:= _
xlYes, OrderCustom:=1, MatchCase:=False, Orientation:= _
xlTopToBottom
' This will do a descending sort, based on data in column D,
' ignoring the header row.
Range("d1").Select
' Clears highlight of list and selects the header of data in
' column D.
End Sub
Sub StopActivateSortRoutine()
ActiveWorkbook.ActiveSheet.OnCalculate = ""
' Stop running the CallSortRoutine macro.
End Sub
Additional query words: XL
Keywords: kbcode kbhowto kbprogramming KB152383