+ Reply to Thread
Results 1 to 12 of 12

Sort a "group" based on cell value

  1. #1
    Registered User
    Join Date
    04-01-2014
    Location
    Denmark
    MS-Off Ver
    Excel 2013
    Posts
    15

    Question Sort a "group" based on cell value

    Hello Community!

    First of all, sorry for the title, I am not sure how to describe the problem shortly.

    I have attached a simplified excel sheet to demonstrate the task I want to have done.

    test2.xlsx

    Column A - unique identifier, based on location of the "group"
    Column B - Main group (not unique)
    Column C - Sub group (unique)
    Column D - Names (each sub-group can have from 1 to infinite names)
    Column E - Amount (one for each name)

    I want it to sort based primarily on column B and secondarily on column C. When sorting, I wont the whole "group", illustrated with the black border, to move together into the correct order without any changes. Don't consider any of the formatting, the only purpose is to illustrate what I want. Besides, it is not important to update Column A when rearranged, I can easily do that in VBA myself.

    The purpose is to have everything from the main group shown together, so when a new entry is added, I can update the list automatically with the click of a button.

    I hope anybody have a solution or at least a clue! I know basic VBA.

    Thank you in advance.

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Sort a "group" based on cell value

    Select the range A2 to E21>>Press F5>>Click Special>>Select Blanks>>Click Ok

    Press = and just press the Up arrow once and press Ctrl+Enter.

    Again select the range A2 to E21 copy and paste it as values using paste special.

    Now apply the sorting as needed


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Registered User
    Join Date
    04-01-2014
    Location
    Denmark
    MS-Off Ver
    Excel 2013
    Posts
    15

    Re: Sort a "group" based on cell value

    First of all, thank you for your reply!

    But, either I don't understand you or you don't understand my problem

    First of all, I would like a hint towards some sort of VBA solution, since I want it done with the click of a button.

    Secondly, when I do what you described, I manage to be able to select all the empty cells, which I then fill with an = sign. Hereafter I can copy and paste special values (which I think I should be able to do anyway), which is not what I am looking for. And I am really not sure what the equal signs are good for. Maybe I'm just being slow here! And sorry for that!

    I am looking for a VBA code which can recognize the "groups", which means, the names and amounts which belongs to a specific subgroup. Hereafter I want it to be able to rearrange the groups so the main groups are groued together, ala sorting according to column B.

    I know how to programatically recognize the group, making it run through column D or E looking for the blank cells which defines when a group ends and a new one starts. With this I can define the group by range(cells(StartRow, 1), Cells(EndRow, 5))

    Something like this:


    Please Login or Register  to view this content.
    BUT! How do I save this range and afterwards sort them? Should it be saved to something like an array? and how?

    EDIT: Just to be clear, I know that I cant say I = 2 to 22, since it wouldn't consider any new entries, but I have a function which finds the end of the data and uses that to limit the loop.

    EDIT 2: with the above-mentioned VBA, no button tho'. test2.xlsm
    Last edited by vkgundersen; 05-08-2014 at 08:09 AM. Reason: additional info

  4. #4
    Registered User
    Join Date
    04-01-2014
    Location
    Denmark
    MS-Off Ver
    Excel 2013
    Posts
    15

    Re: Sort a "group" based on cell value

    sorry, accidently posted below twice!
    Last edited by vkgundersen; 05-08-2014 at 08:17 AM. Reason: Douple post

  5. #5
    Registered User
    Join Date
    04-01-2014
    Location
    Denmark
    MS-Off Ver
    Excel 2013
    Posts
    15

    Re: Sort a "group" based on cell value

    Quote Originally Posted by :) Sixthsense :) View Post
    Select the range A2 to E21>>Press F5>>Click Special>>Select Blanks>>Click Ok

    Press = and just press the Up arrow once and press Ctrl+Enter.

    Again select the range A2 to E21 copy and paste it as values using paste special.

    Now apply the sorting as needed
    Okay okay! Again, sorry! I misunderstood your post before, I made what you said work, but it is still not what I am looking for. But thank you a lot, a quite clever solution tho!

    I want it to stay in the groups as they are. not remove the groups and give everyone its own main and sub group. I know it solves the problem, but firstly, I want an VBA solution, and secondly, removing the groups does not fit into the rest of my code.

  6. #6
    Registered User
    Join Date
    04-01-2014
    Location
    Denmark
    MS-Off Ver
    Excel 2013
    Posts
    15

    Re: Sort a "group" based on cell value

    Bump! (Hope it's allowed, couldn't find anything in the rules)

    Isn't there anybody with a solution or a hint towards a solution? I know basic VBA, so an idea on how to solve this would be much appreciated, it doesn't have to be a complete solution!

  7. #7
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Sort a "group" based on cell value

    I think the vba version of sixthsenses solution would be:
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    04-01-2014
    Location
    Denmark
    MS-Off Ver
    Excel 2013
    Posts
    15

    Re: Sort a "group" based on cell value

    Quote Originally Posted by ragulduy View Post
    I think the vba version of sixthsenses solution would be:
    Please Login or Register  to view this content.
    Thanks a lot! But, as I wrote, I am not interested in a solution which removes the current formatting of the group. It is a part of a bigger system which has been in use for a long time, and changing that part would not be beneficial. I am starting to imagine that what I'm asking might be impossible.

  9. #9
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Sort a "group" based on cell value

    Quote Originally Posted by vkgundersen View Post
    Thanks a lot! But, as I wrote, I am not interested in a solution which removes the current formatting of the group.
    Apply pivot table based on the newly arrived structure, which will get back the original layout

  10. #10
    Registered User
    Join Date
    04-01-2014
    Location
    Denmark
    MS-Off Ver
    Excel 2013
    Posts
    15

    Re: Sort a "group" based on cell value

    Quote Originally Posted by :) Sixthsense :) View Post
    Apply pivot table based on the newly arrived structure, which will get back the original layout
    Okay, thanks

  11. #11
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Sort a "group" based on cell value

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    04-01-2014
    Location
    Denmark
    MS-Off Ver
    Excel 2013
    Posts
    15

    Re: Sort a "group" based on cell value

    ragulduy, that is simply amazing! Thank you!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Adding a group of cells based on a "yes" in another cell
    By mikerules in forum Excel General
    Replies: 2
    Last Post: 04-03-2014, 12:38 AM
  2. How to Group Data based on "Fuzzy" logic in Excel
    By cxlee4 in forum Excel General
    Replies: 1
    Last Post: 11-06-2013, 07:28 PM
  3. Change "Parent" cell based on results of multiple "Children" cells
    By ccowman in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 12-14-2012, 02:33 AM
  4. Split cell values based on "," and "-" and format as shown below
    By Roop in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-22-2012, 12:28 AM
  5. Replies: 1
    Last Post: 04-07-2005, 12:06 PM

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