+ Reply to Thread
Results 1 to 6 of 6

Sorting snake fashion

  1. #1
    Registered User
    Join Date
    01-15-2017
    Location
    Adelaide, Australia
    MS-Off Ver
    2016
    Posts
    3

    Sorting snake fashion

    I'd like to sort sets of xy coordinates in a snake fashion. Say the x coordinate represents a physical row and the y coordinate the location within the row. I want the list to sort first level by x and second level by y but I want the y sort order to reverse when x changes. The resulting list will be used to conduct a survey of the locations, allowing the surveyor to walk down one row and up the next. Sample file attached.
    Would appreciate any ideas.
    Attached Files Attached Files

  2. #2
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Sorting snake fashion

    Hi,

    You won't be able to sort the table within their original columns using formulas, though you can create a separate version of the table which meets the required sorting conditions, viz:

    In H4, simply:

    =A4

    and copied down.

    In I4, array formula**:

    =SMALL(IF(A$4:A$73=H4,B$4:B$73),ABS(IF(ISODD(SUM(N(H$3:H3<>H$4:H4))),0,1+COUNTIF(H$4:H$73,H4))-COUNTIF(H$4:H4,H4)))

    and copied down.

    The formulas for column J I assume you can derive yourself?

    Regards


    **Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  3. #3
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Sorting snake fashion

    Hello okanagan. Welcome to the forum.

    Are you still using Office 2007? If not please update your profile. There are additional tools in newer versions. This helps us help you.
    Dave

  4. #4
    Registered User
    Join Date
    01-15-2017
    Location
    Adelaide, Australia
    MS-Off Ver
    2016
    Posts
    3

    Re: Sorting snake fashion

    Thanks XOR LX, that works great for the y coordinate column. I'm not versed in array formulas so I'll have to spend some time understanding how it works.

    However, I can't get it to work for the value column, which I want to sort with the y coordinates, because each value column entry is an attribute of that particular xy coordinate. But when I adapt your formula for the value column, it sorts by the values.

    No matter, I could get the values where I need them to be by using lookup functions.

    After posting my question and before I got your reply, I continued to think about ways to do the sort and found another way to get the result I need. In case anyone is interested, I did it like this:
    I added a temporary column in which I entered a formula that tests when the x coordinate changes and results in "D" for x coordinates that need regular low to high sorting and "U" for reverse, high to low sorting.
    Like this in cell K5 of my file: =IF(AND(A5=A4,K4="D"),"D",IF(AND(A5=A4,K4="U"),"U",IF(K4="D","U","D"))) and copied to the bottom of the list, after "D" manually entered in K4.
    Then I used a simple data filter and took advantage of how Excel only sorts the visible records of filtered lists.
    So I filtered to show only the "U" rows, then sorted backwards, then unfiltered and had what I needed.

    Thanks again.

  5. #5
    Registered User
    Join Date
    01-15-2017
    Location
    Adelaide, Australia
    MS-Off Ver
    2016
    Posts
    3

    Re: Sorting snake fashion

    Quote Originally Posted by FlameRetired View Post
    Hello okanagan. Welcome to the forum.
    Thanks Dave. After years of finding lots of help on this forum, I finally posted a question!

  6. #6
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,907

    Re: Sorting snake fashion

    One way:

    =AGGREGATE(15-ISEVEN(SUMPRODUCT(--(H$3:H3<>H$4:H4))),6,B$4:B$73/(A$4:A$73=H4),COUNTIF(H$4:H4,H4))

+ 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. snake long rows in one page
    By antonioch1228 in forum Excel General
    Replies: 3
    Last Post: 01-24-2018, 01:00 PM
  2. [SOLVED] Excel Function to number in a snake order
    By Shudodger in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 02-11-2014, 06:47 PM
  3. [SOLVED] Highlighting Cells - In an automated fashion?
    By apalifer in forum Excel General
    Replies: 2
    Last Post: 01-02-2013, 01:24 PM
  4. Snake columns according to cell value instead of row number
    By jassybunny in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-29-2012, 08:13 AM
  5. Snake Count for Fantasy Football
    By Pauleyb in forum Excel General
    Replies: 3
    Last Post: 08-30-2011, 05:43 PM
  6. Copy Data from Column to block... snake style!
    By Karlsson in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-21-2010, 09:00 AM
  7. [SOLVED] ProductIf-that works in a similar fashion
    By ben townson in forum Excel General
    Replies: 1
    Last Post: 06-08-2005, 11:05 AM

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