+ Reply to Thread
Results 1 to 5 of 5

Sorting Data

  1. #1
    Registered User
    Join Date
    12-20-2004
    Posts
    88

    Sorting Data

    I have informations for transactions:
    A1:A10= date
    B1:B10= Name
    C1:C10 = Costs

    There are rows that contain no data. Examle:
    rows 1.3.4,9 may have data
    rows 2,5,6,7,8,10 would be empty

    I'd like to sort the data to elimated the empty rows.

    Thanks
    Travelersway
    Last edited by travelersway; 02-26-2006 at 09:27 PM.

  2. #2
    Max
    Guest

    Re: Sorting Data

    One way .. try tinkering with the 2 subs below

    1. Sub SortAscByDateNameCost()

    Clears A12:C21 first, then copies A1:C10 to A12:C21,
    and then sorts A12:C21 in ascending order
    by Date, then by Name, then by Cost
    (source lines will be kept together)

    2. Sub SortAscIndependently()

    Clears A12:C21 first, then copies A1:C10 to A12:C21,
    and then sorts *independently* each col within A12:C21
    in ascending order (source lines will not be kept together)

    To implement:
    Press Alt+F11 to go to VBE
    Click Insert > Module
    Copy and paste the 2 subs below into the code window
    Press Alt+Q to exit VBE and go back to Excel

    In Excel,
    Click View > Toolbars > Forms
    Click on the button icon and draw a button somewhere on the sheet

    The Assign Macro dialog will pop up
    Look for "SortAscByDateNameCost" in the dialog box, select it > OK
    (or just double-click on "SortAscByDateNameCost")
    The above assigns the Sub SortAscByDateNameCost() to this button.
    Right-click on the button > Edit Text [to rename the button]

    Repeat to draw another button, assign "SortAscIndependently"
    Right-click on the buttons to select, re-position the 2 buttons
    somewhere to the right of A1:C10

    Test out running the 2 subs with your sample data within A1:C10 ..
    (just click the buttons)

    Adapt to suit ..

    '------------
    Sub SortAscByDateNameCost()
    Range("A12:C21").ClearContents
    Range("A1:C10").Copy Destination:=Range("A12")
    Range("A12:C21").Select
    Selection.Sort _
    Key1:=Range("A12"), _
    Order1:=xlAscending, _
    Key2:=Range("B12"), _
    Order2:=xlAscending, _
    Key3:=Range("C12"), _
    Order3:=xlAscending, _
    Header:=xlGuess, _
    OrderCustom:=1, _
    MatchCase:=False, _
    Orientation:=xlTopToBottom
    Range("A1").Select
    End Sub

    Sub SortAscIndependently()
    Range("A12:C21").ClearContents
    Range("A1:C10").Copy Destination:=Range("A12")
    Range("A12:A21").Select
    Selection.Sort Key1:=Range("A12"), _
    Order1:=xlAscending, _
    Header:=xlGuess, _
    OrderCustom:=1, _
    MatchCase:=False, _
    Orientation:=xlTopToBottom
    Range("B12:B21").Select
    Selection.Sort Key1:=Range("B12"), _
    Order1:=xlAscending, _
    Header:=xlGuess, _
    OrderCustom:=1, _
    MatchCase:=False, _
    Orientation:=xlTopToBottom
    Range("C12:C21").Select
    Selection.Sort Key1:=Range("C12"), _
    Order1:=xlAscending, _
    Header:=xlGuess, _
    OrderCustom:=1, _
    MatchCase:=False, _
    Orientation:=xlTopToBottom
    Range("A1").Select
    End Sub
    '----------

    --
    Max
    Singapore
    http://savefile.com/projects/236895
    xdemechanik
    ---
    "travelersway" <[email protected]>
    wrote in message
    news:[email protected]...
    >
    > I have informations for transactions:
    > A1:A10= date
    > B1:B10= Name
    > C1:C10 = Costs
    >
    > There are rows that contain no data. Examle:
    > rows 1.3.4,9 may have data
    > rows 2,5,6,7,8,10 would be empty
    >
    > I'd like to sort the data to elimated the empty rows at the following
    > locations and show 4 consecutive rows of data. :
    >
    > A12:A22= sorted dates
    > B12:B22= Sorted names
    > C12:C22= Sorted costs
    >
    >
    >
    > Any help is appreciated, Thanks
    > Travelersway
    >
    >
    > --
    > travelersway
    > ------------------------------------------------------------------------
    > travelersway's Profile:

    http://www.excelforum.com/member.php...o&userid=17623
    > View this thread: http://www.excelforum.com/showthread...hreadid=516707
    >




  3. #3
    Max
    Guest

    Re: Sorting Data

    > ... I'd like to sort the data to elimated the empty rows.

    If all that you're really after (going by your edited line above)
    is to delete the blank rows within A1:C10,
    then this sub may suffice ..

    Sub RemoveBlankRows()
    Range("A1:C10").Select
    Selection.SpecialCells(xlCellTypeBlanks).Select
    Selection.Delete Shift:=xlUp
    Range("A1").Select
    End Sub

    --
    Max
    Singapore
    http://savefile.com/projects/236895
    xdemechanik
    ---



  4. #4
    Registered User
    Join Date
    12-20-2004
    Posts
    88
    Max,

    Thank you ,Ill try this. Is there a formula that can be written that would perform this automatically without the buttons?

    Thanks again,

    Travelersway

  5. #5
    Max
    Guest

    Re: Sorting Data

    "travelersway" wrote >
    > Max, Thank you ,Ill try this.


    You're welcome !

    > Is there a formula that can be written that
    > would perform this automatically without the buttons?


    Based on your latest "edited" requirement to eliminate empty rows within a
    source range, I don't think so. Formulas can only evaluate/return values in
    the cells they are in, they cannot delete empty rows.

    Try the Sub RemoveBlankRows() in my last response. Think it should work ok.
    Just implement the sub and assign it to a forms toolbar button, as per
    earlier steps provided.
    --
    Max
    Singapore
    http://savefile.com/projects/236895
    xdemechanik
    ---



+ 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