+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 18

Thread: How to sort Grouped data in Excel

  1. #1
    Registered User
    Join Date
    06-30-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    8

    Smile How to sort Grouped data in Excel

    I am working with a huge MS Excel 2010 spreadsheet to track projects and tasks within a project. Each task may have a different delivery date. I would like to group the data by project then sort the projects by earliest delivery date of any task within that project.

    So a simple sample of the data looks as follows:

    COLUMN A COLUMN B COLUMN C
    7/28/2011 Deploy Project Task a
    7/14/2011 AD Project Task b
    7/30/2011 AD Project Task a
    7/18/2011 Deploy Project Task d
    7/20/2011 Condolidation Project Task f
    7/28/2011 Deploy Project Task c

    etc etc

    So, what I am trying to acomplish is how to Group the data in COLUMN B (Project) then sort the Project Groups and each task within that Group by COLUMN A (Delivery date of task) while respecting the groupings. In other words the end result would look something like this:

    7/14/2011 AD Project Task b
    7/30/2011 AD Project Task a

    7/18/2011 Deploy Project Task d
    7/28/2011 Deploy Project Task a
    7/28/2011 Deploy Project Task c

    7/20/2011 Condolidation Project Task f

    Any advice on how to easily acomplish this?

  2. #2
    Forum Guru jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    San Antonio, TX
    MS-Off Ver
    Excel 2007
    Posts
    2,573

    Re: How to sort Grouped data in Excel

    How about a custom sort...

    First by column B, then A, and then C
    HTH
    Regards, Jeff

    If you like the answer(s) provided, why not add some reputation by clicking the * below
    Please use [ Code ] tags when posting [ /Code ]
    Please view/read the Forum rules --- How to mark a thread as solved

  3. #3
    Registered User
    Join Date
    06-30-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: How to sort Grouped data in Excel

    That wouldn't work. It would sort projects by name A to Z or Z to A and then sort the tasks in the projects by delivery but it would not for example bring a project to the top of the list based on delivery date of one of it's tasks. Again I need to group each task row by Project Name THEN sort by earliest task delivery date while respecting the groupings.

    In the example above your solution would bring the Consolidation Project ahead of the Deploy Project because it starts with C even though the Deploy Project has a task due earlier

  4. #4
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,223

    Re: How to sort Grouped data in Excel

    The only way I can see this as manageable is probably with a macro (VBA). Are you ok with a VBA solution?

    To be crystal clear, you should upload a workbook with a BEFORE and an AFTER sheet showing fully what you want to accomplish. Your small dataset above "seems" to present clearly, but think about it now. If we're going to write a macro to reformat your BEFORE dataset into your AFTER dataset, think about it fully now and make sure all the issues that need to be overcome are represented in that data. Expand as needed, then mockup that AFTER sheet.

    Click GO ADVANCED and use the paperclip icon to post up your workbook.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  5. #5
    Valued Forum Contributor MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    5,285

    Re: How to sort Grouped data in Excel

    Hi bool and welcome to the forum,

    I think Jeff may have been right but made a sample file to check his answer. Find attached what I think you are asking. If youi sort by date and then by Project you get the following.

    Let us know if we don't undersand the question.
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * below to say thanks.

  6. #6
    Registered User
    Join Date
    06-30-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    8

    Smile Re: How to sort Grouped data in Excel

    Hi MarvinP,

    Not what I am looking for. In your file, how can Project 1 with its earliest task due on 9/12/11 be sorted first than Project 9 with its earliest task due on 7/211 ?

    The desired outcome in your speadsheet example would be:

    7/2/11 Project 9 Task 49
    8/18/11 Project 9 Task 9
    9/24/11 Project 9 Task 39
    9/28/11 Project 9 Task 29
    11/19/11 Project 9 Task 19
    7/4/11 Project 6 Task 36
    8/13/11 Project 6 Task 16
    8/29/11 Project 6 Task 6
    10/17/11 Project 6 Task 46
    12/12/11 Project 6 Task 26
    7/9/11 Project 7 Task 37
    9/24/11 Project 7 Task 27
    11/24/11 Project 7 Task 47
    12/31/11 Project 7 Task 7
    1/1/12 Project 7 Task 17

    etc, etc

    Notice that I am looking to sort the projects by earliest task due date

  7. #7
    Registered User
    Join Date
    06-30-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    8

    Smile Re: How to sort Grouped data in Excel

    Hello JBeaucaire,

    I am up for any method that will provide an easy solution.

    I am attaching MarvinP's spreadsheet with two tabs that represent the sample data and the desired result after grouping and sorting.

    I am not familiar with macros or VBA

    Thank you!
    Attached Files Attached Files

  8. #8
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,223

    Re: How to sort Grouped data in Excel

    Try this:

    Option Explicit
    
    Sub SortSpecial()
    Dim LR As Long
    
    LR = Range("A" & Rows.Count).End(xlUp).Row
    
    With Range("A1:C" & LR)
        .Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, _
            OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
            DataOption1:=xlSortTextAsNumbers
        .Sort Key1:=Range("B2"), Order1:=xlAscending, Header:=xlGuess, _
            OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
            DataOption1:=xlSortNormal
    End With
        
    With Range("A2:A" & LR)
        .FormatConditions.Delete
        .FormatConditions.Add Type:=xlExpression, Formula1:= _
            "=COUNTIF($B$1:$B1,$B1)=1"
        With .FormatConditions(1).Font
            .Bold = True
            .Italic = False
        End With
    End With
    End Sub
    Attached Files Attached Files
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  9. #9
    Valued Forum Contributor MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    5,285

    Re: How to sort Grouped data in Excel

    Ok bool,

    See the attached. I've created a pivot table of the data where the rows are Project first. Then the summation is the MIN of the date for each Project. Then I added Task in Row area.

    To test this - Change any date or field in the Data (Cols A to C) and see the Pivot Refresh with an Event Macro behind sheet 1.

    This was a very tough problem but I think this solves it for you.
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * below to say thanks.

  10. #10
    Forum Guru martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    10,788

    Re: How to sort Grouped data in Excel

    in marvins example to get the result you show
    sort the lot by column a
    in d2 put this array entered formula
    =MIN(IF($B$2:$B$51=B2,$A$2:$A$51,""))&B2
    confirmed with ctrl+ shift+enter
    drag down to last entry in col a
    now sort by column d
    Attached Files Attached Files
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and a dabbler in Cisco
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  11. #11
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    Apparently I can't say
    MS-Off Ver
    Apparently I can't say
    Posts
    8,274

    Re: How to sort Grouped data in Excel

    Simple non-code method:
    1. Sort the data by Project.
    2. Data - subtotals, at change in Project use Min of Delivery date.
    3. Collapse data so only subtotals visible.
    4. Select and sort by Delivery date
    5. Remove subtotals.

  12. #12
    Valued Forum Contributor MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    5,285

    Re: How to sort Grouped data in Excel

    @romperstomper -
    I've never worked with the Subtotal dialog. It looks like a winner for this problem. Is there a way to do this using the Subtotal Function in a helper column?
    Finding the Subtotal Dialog was like finding another blade on my swiss army knife of tools. Thanks for showing it to me/us.

    Marv
    One test is worth a thousand opinions.
    Click the * below to say thanks.

  13. #13
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    Apparently I can't say
    MS-Off Ver
    Apparently I can't say
    Posts
    8,274

    Re: How to sort Grouped data in Excel

    Not easily no as you would have to work out what ranges to apply it to (in which case you might as well use Min)

  14. #14
    Registered User
    Join Date
    06-30-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: How to sort Grouped data in Excel

    Thanks to Everyone for the solutions. I set to try all three solutions from simplest to more complex: Sub-totals, Pivot Table, VBA Script

    I give romperstomper the lead as his solution was the simplest (1-2 mins to implement) and provides the desired results. Thanks romperstomper!

  15. #15
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    Apparently I can't say
    MS-Off Ver
    Apparently I can't say
    Posts
    8,274

    Re: How to sort Grouped data in Excel

    Glad to help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0