+ Reply to Thread
Results 1 to 5 of 5

Sort by three columns, using formulas

  1. #1
    Registered User
    Join Date
    10-17-2019
    Location
    Hungary
    MS-Off Ver
    2003
    Posts
    3

    Sort by three columns, using formulas

    Hello everyone,

    I'm working on an excel table that handles electric cable types. The general structure of a cable type looks like: "cable name" "number of wires"x"wire cross section"mm2. For example, such a cable type looks like: NYY_J 4x240mm2. In my excel the list of cables need to be handled dynamically, because they are given as inputs, using drop down menus. And also, the number of cables in the list can vary. The task I am trying to achieve is that I want these cable types sorted. The first level of the sorting should base on the cable type, then the second on the number of wires, and lastly on the wire cross section. For example such a sorted list should look like: NYY_J 4x25mm2, NYY_J 4x240mm2, YSLY 3x1,5mm2, YSLY 4x1,5mm2, YSLY 4x50mm2. (Note: sorting only the whole strings do not work, because they are handled as texts, therefore 240 comes before 25)

    I managed to seperate the three parts of the cable type. The cable name is kept as text, and the number of wires and wire cross sections are converted to numbers, all in three different columns. I have successfully sorted the cable names alphabetically, then I also managed to sort the number of wires. Unfortunately I can't figure it out, how should I sort the last column (wire cross section) based on the two previous ones.

    I have attached the .xls file I'm working on. The headers are in Hungarian (sorry for that). The part, which I have trouble with is located on the worksheet called "Kigyűjtések", from C18, to K32. It's important, that I'm trying to make this table Excel 2003 compatible, so I'm only using functions and formulas that are available in 2003. In column D the duplicates are filtered out from the original list, then in column E, F and G the three parts of the cable type are separated. In column "I" the cable names are sorted, and in column J the number of wires are also sorted, based on the cable name. I would like to fill the column K with the sorted wire cross sections, based on the previous two columns. Then I would merge back the three components into one in the column L (this would be the easy part).

    I would be really-really grateful if you could help me with this problem. Any other suggestions, or a completely another approach that leads to the cable types being sorted the way I described are also welcome.
    Attached Files Attached Files

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: Sort by three columns, using formulas

    For the 1st part...
    =LEFT(D18,FIND(" ",D18)-1)
    for the middle...
    =--MID(D18,LEN(E18)+1,2)
    For the last part...
    =--SUBSTITUTE(SUBSTITUTE(MID(D18,FIND("x",D18)+1,99),"mm2",""),",",".")
    if you want to leave that last 1 as text, remove the 1st SUBSTITUTE

    Once you have those 3 extracted, you should be able to sort your data based on those 3 columns
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Registered User
    Join Date
    10-17-2019
    Location
    Hungary
    MS-Off Ver
    2003
    Posts
    3

    Re: Sort by three columns, using formulas

    Thank you for your reply!

    You probably misunderstood, or I wasn't completely clear about my issue. The table I attached previously have already contained these columns that separate the three parts of the cable type. I was having trouble to sort them with the use of formulas. I mean I wanted to handle everything dynamically, because any time a new cable can added, or an already existing can be modified. In the previously attached table, I managed to work out the first two levels of the sorting, the only trouble was with the third level.

    Anyway, I've decided to move on (and it will be time for my colleagues, too ), and upgraded to Excel 2010. That is, because now I can use the COUNTIFS function, which makes the sorting so much easier. So I'd just like to share the working solution. Firstly the COUNTIFS functions are used to determine the ranks of cable types (all three components ranked in a singe formula):
    =COUNTIF($E$18:$E$167,"<"&E18)+COUNTIFS($E$18:$E$167,$E18,$F$18:$F$167,"<"&$F18)+COUNTIFS($E$18:$E$167,$E18,$F$18:$F$167,$F18;$G$18:$G$167,"<"&$G18)+1
    Then simply INDEX and MATCH functions are used to sort the cables, based on their ranks:
    =INDEX($D$18:$D$167,MATCH(ROWS($I$18:I18),$H$18:$H$167,0))

    So I managed to work around my problem. But if anyone had a solution that also works in Excel 2003, I would still be interested. But anyway, thank you for your help.
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    09-30-2019
    Location
    Chiangmai, Thailand
    MS-Off Ver
    Office 2016, Excel 2019
    Posts
    1,234

    Re: Sort by three columns, using formulas

    This file might be fit (or help a little >_<) your requirement.

    I can not explain well.

    Just to tell that , use formula to re-config your product name to (Name)(1_space)(core-000 3 digits)x(diameter-0000.00 7 digits)mm2 and
    build into a array list with this formula. [Note: Name must not contains spaces]

    Please Login or Register  to view this content.
    Then use Dave Bruns's formula to ranking all product together.
    Please Login or Register  to view this content.
    and rebuild a non-blank sorted product.
    Please Login or Register  to view this content.
    [ from 20'th row to 165'th row ]



    Regards.
    Attached Files Attached Files
    Last edited by menem; 10-20-2019 at 05:28 AM. Reason: Add code tags

  5. #5
    Registered User
    Join Date
    10-17-2019
    Location
    Hungary
    MS-Off Ver
    2003
    Posts
    3

    Re: Sort by three columns, using formulas

    Thank you very much for your help. Not everything is clear yet, but I'm trying to understand the idea.

+ 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. How to sort two columns but one has formulas
    By Marvin85 in forum Excel General
    Replies: 7
    Last Post: 03-27-2015, 03:02 PM
  2. [SOLVED] How do I sort columns with IF formulas in them?
    By Kristine in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 04-27-2006, 04:15 PM
  3. [SOLVED] Sort &amp;amp; add columns without messing up formulas
    By kate in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-08-2005, 12:05 PM

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.6.0 RC 1