+ Reply to Thread
Results 1 to 2 of 2

Moving "sort by column"

  1. #1
    brian
    Guest

    Moving "sort by column"

    I am trying to write a macro to automatically sort a small section of a
    database of stock prices (see below) by referencing the column where the
    current date is located, currently at "AW5".

    Code 17/07/06 18/07/06 19/07/06
    AAC 1.80 1.85 1.86
    AAE 0.64 0.63 0.63
    AAI 42.75 42.75 42.75
    AAM 0.24 0.22 0.21
    AAO 0.14 0.15 0.15

    At this point, Excel generated the following codes for me:

    Selection.Sort Key1:=Range("AW5"), Order1:=xlAscending, Header:=xlNo, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal

    However, after adding a new set of column data the next day, the date
    location changes to "AX5", and the "sort by column" is now one column to the
    right. How can I modify the macro to automatically sort by the new "date
    column" ? Any help would be much appreciated.

    TIA
    Brian



  2. #2
    FSt1
    Guest

    RE: Moving "sort by column"

    hi,
    i assume that since you add a column each day that all the columns to the
    right are blank. if so then this may do what you want.

    sub sortmovecol()
    Range("IV5").End(xlToLeft).Select
    ActiveSheet.UsedRange.Sort Key1:=Selection, Order1:=xlAscending,
    Header:= _
    xlGuess, OrderCustom:=1, MatchCase:=False,
    Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal
    end sub

    regards
    FSt1

    "brian" wrote:

    > I am trying to write a macro to automatically sort a small section of a
    > database of stock prices (see below) by referencing the column where the
    > current date is located, currently at "AW5".
    >
    > Code 17/07/06 18/07/06 19/07/06
    > AAC 1.80 1.85 1.86
    > AAE 0.64 0.63 0.63
    > AAI 42.75 42.75 42.75
    > AAM 0.24 0.22 0.21
    > AAO 0.14 0.15 0.15
    >
    > At this point, Excel generated the following codes for me:
    >
    > Selection.Sort Key1:=Range("AW5"), Order1:=xlAscending, Header:=xlNo, _
    > OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    > DataOption1:=xlSortNormal
    >
    > However, after adding a new set of column data the next day, the date
    > location changes to "AX5", and the "sort by column" is now one column to the
    > right. How can I modify the macro to automatically sort by the new "date
    > column" ? Any help would be much appreciated.
    >
    > TIA
    > Brian
    >
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1