+ Reply to Thread
Results 1 to 5 of 5

Sorting on four coloumns

  1. #1
    Registered User
    Join Date
    09-26-2011
    Location
    DE
    MS-Off Ver
    Excel 2003
    Posts
    38

    Sorting on four coloumns

    Hi,

    I have the following sheet and code which at the moment are not working as it should be. What I want is to sort

    1) First Colounm F,
    2) Then Colounm B,
    3) Then Colounm D,
    4) and last Colounm E

    Please advice how I can add the fourth sorting so the above ranking is applied.

    Thanks!
    Attached Files Attached Files

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Sorting on four coloumns

    .
    There is probably a 'prettier' way to do this, however running the Macro Recorder results in this code which gets the job done:

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    09-26-2011
    Location
    DE
    MS-Off Ver
    Excel 2003
    Posts
    38

    Re: Sorting on four coloumns

    Hi Logit,

    Maybe I did not expressed myself well enough.
    The data in column A:F is a dataset and therefore I need to make the above sorting (F, B, D, E) for the whole dataset and not just taking one coloumn after eachother.

    Also, I have some data above in row 1 so I can't just take "whole" coloumns but need to sort in the specific "data field".

    Appreciate the feedback
    Last edited by Jabj; 01-20-2017 at 02:52 AM.

  4. #4
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Sorting on four coloumns

    Hi Jabj,

    Your profile indicates you are using Excel 2003. To the best of my knowledge, without trickery, Excel 2003 can only sort 3 columns.

    However if you add a 'Helper Column', you may be able to do what you want. Since your test file does not include any data in Column 'F', the following is a hypothetical.

    Data as follows:
    a. Text or Number in Column 'F' (ffff)
    b. Text or Number in Column 'B' (bbbb)
    c. Date in Column 'D' (March 11, 2017)
    d. Text or Number in Column 'E' (1.233)

    a. Create a Helper Column that concatenates the data you want to sort in the order you want the data sorted. The LEFT function creates a string padded with spaces. The spaces are needed to make sure each field sorts correctly. If the LEFT function contains the number 20, make sure there are at least 20 spaces between the double quotes.
    b. Include the Helper Column in your data, and sort with the Helper Column as the key.
    c. The Helper Column can be hidden to preserve PRETTY PRINT for your data.


    Formula: copy to clipboard
    Please Login or Register  to view this content.


    The formula will create a text string that looks like:
    Please Login or Register  to view this content.
    NOTE: apostrophes are NOT in the text string'

    I hope this helps.

    Lewis

  5. #5
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Sorting on four coloumns

    The example has data in A to E, not A to F, if that's the case this code may not work, but in theory this should do what you ask? It first sorts by E, then does the other 3, which makes E the last sort criteria.

    Please Login or Register  to view this content.
    Last edited by Arkadi; 01-24-2017 at 04:28 PM.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

+ 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] How to put x and numbering every other 2 Coloumns.
    By Rafa100 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-22-2015, 08:44 AM
  2. Minimum value of last row in several coloumns
    By RorschachDK in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-09-2014, 05:43 PM
  3. VBA code to consolidate coloumns in muliple sheets into multiple coloumns in one sheet?
    By BrettRCourtney in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-13-2013, 09:17 AM
  4. [SOLVED] VBA code to consolidate coloumns in muliple sheets into multiple coloumns in one sheet?
    By BrettRCourtney in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-13-2013, 06:19 AM
  5. Excel 2007 : Comparing 2 Coloumns
    By UselessMan in forum Excel General
    Replies: 0
    Last Post: 09-23-2011, 04:24 PM
  6. Grouping of 2 Coloumns
    By lovinguy in forum Excel General
    Replies: 2
    Last Post: 12-16-2010, 04:10 PM
  7. difference between coloumns
    By rds207 in forum Excel General
    Replies: 2
    Last Post: 08-17-2009, 08:28 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