+ Reply to Thread
Results 1 to 4 of 4

Macro Sorts In Wrong Order

  1. #1
    Registered User
    Join Date
    06-30-2007
    Posts
    26

    Macro Sorts In Wrong Order

    I have a macro that works, but not as efficient as I need,

    Its used for creating a list of forced shift changes. If someone is forced to amend their shift, they should then go to the bottom of the list. The only way I can do it is to use the date of the shift change. This is fine, but if i change say 3 people on the same date. They see to stack wrong: i.e

    First Col is Starting List
    Second Col is My Current Results
    Third Col is the Desired Result required

    1 4 4
    2 5 5
    3 6 6
    4 7 7
    5 8 8
    6 9 9
    7 10 10
    8 11 11
    9 12 12
    10 3 1
    11 2 2
    12 1 3


    This is my Macro:

    Sub Button1_Click()
    '

    '

    Sheets("FROM NIGHTS").Select
    Range("C4:I20").Select
    Selection.Sort Key1:=Range("D5"), Order1:=xlAscending, Header:=xlGuess, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
    Range("C4").Select
    End Sub

    Any help would be welcomed. Basically if two changes are made for the same date, I want the second one to go below the first one and not above the first one as in my results

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Please read forum rules & wrap your VBA code - see links below for rules


    If you do not understand the VBA code wrap instructions have a look at my last reply in this thread
    http://www.excelforum.com/showthread.php?t=583950
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  3. #3
    Registered User
    Join Date
    06-30-2007
    Posts
    26
    Apologies. second attempt.

    I have a macro that works, but not as efficient as I need,

    Its used for creating a list of forced shift changes. If someone is forced to amend their shift, they should then go to the bottom of the list. The only way I can do it is to use the date of the shift change. This is fine, but if i change say 3 people on the same date. They see to stack wrong: i.e

    First Col is Starting List
    Second Col is My Current Results
    Third Col is the Desired Result required

    1 4 4
    2 5 5
    3 6 6
    4 7 7
    5 8 8
    6 9 9
    7 10 10
    8 11 11
    9 12 12
    10 3 1
    11 2 2
    12 1 3

    This is my Macro:

    Please Login or Register  to view this content.
    Any help would be welcomed. Basically if two changes are made for the same date, I want the second one to go below the first one and not above the first one as in my results

  4. #4
    Forum Contributor
    Join Date
    07-05-2007
    Location
    Lexington, MA
    Posts
    302
    Excel sorts on the column(s) you specify. Within matching key values, it preserves the original order of the rows. So, if you enter three rows under one keyvalue, that original row order is preserved. To do the sorting more finely, you may need to record the date and time and sort on that.
    FrankBoston is the pen name for Andrew Garland, Lexington MA

+ 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