+ Reply to Thread
Results 1 to 39 of 39

Sort column 2 different ways.

  1. #1
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Covilhã
    MS-Off Ver
    2010
    Posts
    516

    Sort column 2 different ways.

    Hello all,

    Hope someone can help me with my problem.

    I need to sort The same column 2 different ways.

    For the first i Need to sort by "SIM" THEN "NO"

    INSIDE YES, sort by name and then measure.
    INSIDE NO, sort only by measure.

    Hope you can help me.
    Attached Files Attached Files

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Sort column 2 different ways.

    I wonder if you really mean SORT as we all understand it. If so can't you just sort with Brand as the primary key sorted descending, and Name as the secondary key ascending.

    If not explain how you get A, A, B, C with 20, 30, 60, 85 in H2:H5 when these are nor shown in the A1:C9 table.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Covilhã
    MS-Off Ver
    2010
    Posts
    516

    Re: Sort column 2 different ways.

    Quote Originally Posted by Richard Buttrey View Post
    I wonder if you really mean SORT as we all understand it. If so can't you just sort with Brand as the primary key sorted descending, and Name as the secondary key ascending.

    If not explain how you get A, A, B, C with 20, 30, 60, 85 in H2:H5 when these are nor shown in the A1:C9 table.
    Hello Mr. Richard,

    Thanks in advance for your help.

    I mean sort as you all understand.

    Understand for the BRAND "YES" i need to sort by name and then by measures.

    For the brand "NO" i just need to sort by measures, measures are priority.

    About the table, it was wrong.
    BRAND NAME MEASURE
    YES A 20
    YES A 85
    YES B 30
    YES C 60
    NO G 15
    NO E 26
    NO Z 50
    NO F 60

    This is what i need to have. if yes, sort name then measure.
    If no, sort by measure, and put name according
    Attached Files Attached Files

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Sort column 2 different ways.

    ...in that case just add a third sort level and sort on MEASURE ascending.

  5. #5
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Covilhã
    MS-Off Ver
    2010
    Posts
    516

    Re: Sort column 2 different ways.

    Quote Originally Posted by Richard Buttrey View Post
    ...in that case just add a third sort level and sort on MEASURE ascending.
    Although if if do everything together it will sort the same for YES And NO.

    I have this:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Sort column 2 different ways.

    What is it about my suggestion that doesn't work with the example data you showed. The sorting method I gave gives you the results you showed you wanted.

    If however your real data is different in layout and size then upload an example that contains your real data and manually add the results you expect.

  7. #7
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Covilhã
    MS-Off Ver
    2010
    Posts
    516

    Re: Sort column 2 different ways.

    Quote Originally Posted by Richard Buttrey View Post
    What is it about my suggestion that doesn't work with the example data you showed. The sorting method I gave gives you the results you showed you wanted.

    If however your real data is different in layout and size then upload an example that contains your real data and manually add the results you expect.
    Hello Richard, can you confirm me if what you mean i should do is what i did in the last code i sent?

    Cuz according to that:
    "BRAND" is sorted correctly
    Although NAME is sort for all BRANDS instead of only "YES" brand..

    If possible send me the code or correct the one i sent.

    Thanks in advance.

  8. #8
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Covilhã
    MS-Off Ver
    2010
    Posts
    516

    Re: Sort column 2 different ways.

    Quote Originally Posted by Richard Buttrey View Post
    What is it about my suggestion that doesn't work with the example data you showed. The sorting method I gave gives you the results you showed you wanted.

    If however your real data is different in layout and size then upload an example that contains your real data and manually add the results you expect.
    If you need more information let me know. thanks for your time.

  9. #9
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Sort column 2 different ways.

    ... as I said please upload your workbook with some manually added results so that I can see your goal.

  10. #10
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Covilhã
    MS-Off Ver
    2010
    Posts
    516

    Re: Sort column 2 different ways.

    Quote Originally Posted by Richard Buttrey View Post
    ... as I said please upload your workbook with some manually added results so that I can see your goal.
    See if you can help me out with the new file attach.

    LEFT SIDE is my data, in the right side is what i NEED.

    ORDER 1 COLUMN for YES then NO
    Inside YES, order 2nd column from A to Z and 3rd column ascending.
    Inside NO, order 3rd column ascending only. (don't sort 2nd column A to Z)

    Hope you can understand my need and my goal.

    Get back to me as soon as possible
    Attached Files Attached Files
    Last edited by brainzlp; 11-23-2015 at 10:51 AM.

  11. #11
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Sort column 2 different ways.

    Does this help?

    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Covilhã
    MS-Off Ver
    2010
    Posts
    516

    Re: Sort column 2 different ways.

    Quote Originally Posted by JOHN H. DAVIS View Post
    Does this help?

    Please Login or Register  to view this content.
    Just clarify me some things:

    What does this means?
    Please Login or Register  to view this content.
    What is the 3 ?

    Where is the sort for YES first then No? here:
    Please Login or Register  to view this content.
    ?

  13. #13
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Sort column 2 different ways.

    x Stands for the last cell with data in Column "A"

    Please Login or Register  to view this content.
    (3) is a short form for xlup - Means the same (3) or (xlUp)

    When you sort the column "A" descending Alphabetically the YES's will be on Top and then the "NO's".

    Did you test the code too see if it does what you want?

  14. #14
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Covilhã
    MS-Off Ver
    2010
    Posts
    516

    Re: Sort column 2 different ways.

    ignore this

  15. #15
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Covilhã
    MS-Off Ver
    2010
    Posts
    516

    Re: Sort column 2 different ways.

    My problem is that i will filter this first, so this needs to be flexible.

    I think if i put:
    Please Login or Register  to view this content.
    The 2 means the 1st data row and column correct?

    Please Login or Register  to view this content.
    The 3 means the Total columns of data correct?

    I already tested the code on the easy workbook, now i'm putting in the large one after filts and see what's going on

  16. #16
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Covilhã
    MS-Off Ver
    2010
    Posts
    516

    Re: Sort column 2 different ways.

    I've sent you a sample in this comment of my file.

    Can you please help me out modifying the initial code to meet my goal?

    Please Login or Register  to view this content.
    The brand is column: M
    The Name is column: N
    The measures is column: X
    Attached Files Attached Files

  17. #17
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Sort column 2 different ways.

    The 3 in this case means Column "C", if you want to apply it too the used range use this instead.

    Please Login or Register  to view this content.

  18. #18
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Sort column 2 different ways.

    Maybe:

    Please Login or Register  to view this content.

  19. #19
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Covilhã
    MS-Off Ver
    2010
    Posts
    516

    Re: Sort column 2 different ways.

    Quote Originally Posted by JOHN H. DAVIS View Post
    Maybe:

    Please Login or Register  to view this content.
    Hello Mr. John,

    Thanks for your help.

    Let me know if i can use something like:

    Please Login or Register  to view this content.
    To select the first visible row, instead of:
    Please Login or Register  to view this content.
    Another thing i don't understand is:
    Please Login or Register  to view this content.
    Why is "A" And "B" , Is it correct?

  20. #20
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Sort column 2 different ways.

    My mistake:

    In your sample the Header info ends on row 6 and the data begins on row 7.

    Therefore Range(cells(7,1....

    Please Login or Register  to view this content.
    Key2 is commented out, but here I've removed it. It was a mistake. r.row is the row where "NO" begins after the sort. Did you test the code?

  21. #21
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Covilhã
    MS-Off Ver
    2010
    Posts
    516

    Re: Sort column 2 different ways.

    Quote Originally Posted by JOHN H. DAVIS View Post
    My mistake:

    In your sample the Header info ends on row 6 and the data begins on row 7.

    Therefore Range(cells(7,1....

    Please Login or Register  to view this content.
    Key2 is commented out, but here I've removed it. It was a mistake. r.row is the row where "NO" begins after the sort. Did you test the code?
    Hello Mr. John,

    I've tried your code but it isn't working.

    Please Login or Register  to view this content.
    You can check in my attached file, run brainzlp macro. See that when "SIM" is there, the measures (X column) DOESN'T sort.
    Attached Files Attached Files

  22. #22
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Sort column 2 different ways.

    @Brainzip

    Please note that including previous quoted text in a response should be used extremely sparingly.
    Most of the time it isn't necessary and when it is should only include that RELEVANT subset of text that is necessary to draw particular attention to a point.

  23. #23
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Sort column 2 different ways.

    Column "X" Works for me.

  24. #24
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Covilhã
    MS-Off Ver
    2010
    Posts
    516

    Re: Sort column 2 different ways.

    Quote Originally Posted by JOHN H. DAVIS View Post
    Column "X" Works for me.
    I'm sorry but for me it doesn't work.

    It works when brand is "NÃO" although when it is "YES" the X column is not sorted.

    Can you please check it?

    In the "YES" brand, the X column must be 60 then 70..

    Am i misreading the map?

  25. #25
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Covilhã
    MS-Off Ver
    2010
    Posts
    516

    Re: Sort column 2 different ways.

    @Richard Buttrey


    Noted it. Thanks for information.

  26. #26
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Covilhã
    MS-Off Ver
    2010
    Posts
    516

    Re: Sort column 2 different ways.

    @JOHN H. DAVIS

    Works perfectly, code was incorrect for my fault.

    I don't want to sort N column but P column.

    It's solved.
    Please Login or Register  to view this content.

    Although i tried with more data, and inside "NÃO" it's not giving priority to MEasures, it's sorting by name as well..

  27. #27
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Covilhã
    MS-Off Ver
    2010
    Posts
    516

    Re: Sort column 2 different ways.

    Check file in attach.

    You have there more that, and check that when brand is "NÃO" the measures are not sorted out.

    You have the macro inside the workbook as well
    Attached Files Attached Files

  28. #28
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Covilhã
    MS-Off Ver
    2010
    Posts
    516

    Re: Sort column 2 different ways.

    I already made some attempts but can't put this working.

    My goal really is:

    1st need to Sort by Yes then NO in M Column (Marca)

    Within Yes -> Sort P Column (Nome Flexo) -> then Sort X column (Largura)
    Within No -> Sort X column (Largura) Only

    Any information

  29. #29
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Sort column 2 different ways.

    Does "SIM" mean "YES" ? If so then try:

    Please Login or Register  to view this content.

  30. #30
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Covilhã
    MS-Off Ver
    2010
    Posts
    516
    Yes, Sim = Yes, i will try as soon as i have the computer with me, 10 min and i get back again to you with feedback

  31. #31
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Covilhã
    MS-Off Ver
    2010
    Posts
    516

    Re: Sort column 2 different ways.

    HI, i've already tested, for the "NÃO" it's fine now.

    Although in YES, it's not sorting firstly for name.

    As you can see after running macro, the names are: tapasol r3d, centro centro , tapasol R3D.

    They must be gathered.

    Hope you can help with this

  32. #32
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Covilhã
    MS-Off Ver
    2010
    Posts
    516

    Re: Sort column 2 different ways.

    Duplicated by bug. Sorry.
    Last edited by brainzlp; 11-23-2015 at 03:42 PM.

  33. #33
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Covilhã
    MS-Off Ver
    2010
    Posts
    516

    Re: Sort column 2 different ways.

    Duplicated by bug. Sorry.
    Last edited by brainzlp; 11-23-2015 at 03:42 PM.

  34. #34
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Sort column 2 different ways.

    Quote Originally Posted by brainzlp View Post
    @ Richard Buttrey
    Noted it. Thanks for information.
    .... and thanks for the acknowledgment.

  35. #35
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Covilhã
    MS-Off Ver
    2010
    Posts
    516

    Re: Sort column 2 different ways.

    Mr. JOHN,

    Thanks for your help, with your code i managed to put this working as needed.

    Please Login or Register  to view this content.

    Just some questions so i can understand and improve.

    End(3) = end(Xlup) ?
    Columns(13) , 13 means the number of the column in "brand" (Marca) correct?

    r.row - 1 , why do we have to take 1 to the ROw number?

  36. #36
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Sort column 2 different ways.

    End(3) - Yes (xlUp)
    No Columns(13) - means Columns(M) - The 13th Column of the spreadsheet
    r.row -1 - It offsets -1 from the first cell with "NAO" and sorts on the range above it.

  37. #37
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Covilhã
    MS-Off Ver
    2010
    Posts
    516

    Re: Sort column 2 different ways.

    Quote Originally Posted by JOHN H. DAVIS View Post
    End(3) - Yes (xlUp)
    No Columns(13) - means Columns(M) - The 13th Column of the spreadsheet
    r.row -1 - It offsets -1 from the first cell with "NAO" and sorts on the range above it.
    I already tried and seems to work if i have "SIM" and "NO" or just "SIM"

    Although if all column is with "NO" which can occur once in a while, it gives an error.

  38. #38
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Sort column 2 different ways.

    Try:

    Please Login or Register  to view this content.

  39. #39
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Covilhã
    MS-Off Ver
    2010
    Posts
    516

    Re: Sort column 2 different ways.

    Hello Mr. John,

    I've tried but it doesn't sort nothing any "SIM" values.

    I'll opt for this, although it's
    Please Login or Register  to view this content.

+ 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. Replies: 1
    Last Post: 03-04-2015, 02:57 PM
  2. [SOLVED] I have a sort macro. How to add script to preselect rows to sort based on column value?
    By Jasonhouse in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-09-2014, 02:25 AM
  3. Replies: 2
    Last Post: 01-15-2014, 09:31 AM
  4. [SOLVED] Move currency symbol into another column by Regex or by other ways
    By taps in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-18-2013, 06:16 AM
  5. Can you sort a pivot field two ways?
    By cch70 in forum Excel General
    Replies: 1
    Last Post: 03-09-2011, 07:08 PM
  6. Replies: 3
    Last Post: 05-17-2009, 04:31 AM
  7. Formula Reference Row To Column, Scroll Ways!
    By rr1050 in forum Excel General
    Replies: 4
    Last Post: 01-05-2009, 07:54 AM

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