+ Reply to Thread
Results 1 to 11 of 11

How to sort and switch the data in the first column and the rest? (With an example)

  1. #1
    Registered User
    Join Date
    06-15-2018
    Location
    Vancouver
    MS-Off Ver
    Office 365
    Posts
    4

    How to sort and switch the data in the first column and the rest? (With an example)

    I don't know how to describe this problem accurately so here is an example. The original sheet looks like this:

    a 1 6 7 8 10

    b 3 4 9 10

    c 1 2 3 4 5

    d 1 4 5 8 11

    e 2 3 6

    f 5 6 7 10 11

    g 4 5 7 8 10

    Now I want to rearrange this table and put the numbers in the first column, which indicates which numbers "own" which letters, like this:

    1 a c d

    2 c e

    3 b e

    4 b c d g

    5 c d f g

    6 a e f

    7 a f g

    8 a d g

    9 b

    10 a b f g

    11 d f

    I did this manually but does anybody know if there is an easier way to do this? BTW in the real case, all the letters and numbers are names of people or things.

    Thank you!

  2. #2
    Registered User
    Join Date
    04-14-2014
    Location
    Philippines
    MS-Off Ver
    Excel 2010
    Posts
    97

    Re: How to sort and switch the data in the first column and the rest? (With an example)

    You can attached a sample of your worksheet to have clear idea of your problem.

    It seems that your sample above are different from your result.

    regards,
    Rev12

  3. #3
    Registered User
    Join Date
    06-15-2018
    Location
    Vancouver
    MS-Off Ver
    Office 365
    Posts
    4

    Re: How to sort and switch the data in the first column and the rest? (With an example)

    Thanks Rev12. I tried to upload a screenshot but failed. I copied and pasted the text instead. It's the same. I did the work manually so there might be some typo.

    To put it in a simpler way, just how to change a sheet from:

    a 1 2
    b 2 3 6
    c 3 4 5

    into

    1 a
    2 a b
    3 b c
    4 c
    5 c
    6 b


    Someone suggests pivot table. I'll check out some tutorial later but I'd appreciate it if someone could provide a detailed solution.

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: How to sort and switch the data in the first column and the rest? (With an example)

    Hi TruthGuy and welcome to the forum,

    I needed to do an UnPivot of your data using Power Query and then added a Helper column to do the final array formula. See the attached. This isn't an easy problem but it can be done.

    UnPivot Truthguy.xlsx
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  5. #5
    Registered User
    Join Date
    06-15-2018
    Location
    Vancouver
    MS-Off Ver
    Office 365
    Posts
    4

    Re: How to sort and switch the data in the first column and the rest? (With an example)

    Thanks a lot MarvinP! I gotta figure out how to use pivot table to better understand this.

  6. #6
    Registered User
    Join Date
    06-13-2018
    Location
    india
    MS-Off Ver
    2010;2007
    Posts
    54

    Re: How to sort and switch the data in the first column and the rest? (With an example)

    A completely formula based solution without helper column

    I am considering example from 1st post and assuming that your example from post #1 ranges from A1 and goes till F7

    below formula is to extract the numbers in one column from data copy paste below formula in H1 then hold Ctrl+Shft and then Hit enter to make it array
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    drag down

    now in I1 use below formula and then drag down and drag right to get result, copy paste below in I1 and the hold CTRL+SHIFT and then hit enter
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    change the ranges to suit your need

    if this helps then add reputation by clicking little star button at the bottom of this post
    Attached Files Attached Files

  7. #7
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: How to sort and switch the data in the first column and the rest? (With an example)

    Hi truthguy,

    I really didn't do any "Pivot Table" in solving your problem. Your data needs to be transformed to a table with two columns and a repeat of the numbers and letters for Excel to work effectively with it. The UnPivot that I did is found in a "Get & Transform" tool which is newer to Excel. It is found on the Data Tab. It is known as "Power Query" in earlier versions of Excel (2010 and 2013) but is now standard in 2016.


    After your data is in two columns (on sheet 2) I added a 3rd column called Helper to count the repeated numbers. Then I applied the formula in the table to the right. Look at my attached in my post above. Your problem is NOT trivial. It is harder than the normal novice would be able to solve.

  8. #8
    Registered User
    Join Date
    06-15-2018
    Location
    Vancouver
    MS-Off Ver
    Office 365
    Posts
    4

    Re: How to sort and switch the data in the first column and the rest? (With an example)

    Thank you guys so much!

  9. #9
    Registered User
    Join Date
    06-13-2018
    Location
    india
    MS-Off Ver
    2010;2007
    Posts
    54

    Re: How to sort and switch the data in the first column and the rest? (With an example)

    Thanks for the reply and rep truthguy!

  10. #10
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Cool Re: How to sort and switch the data in the first column and the rest? (With an example)

    everything with PowerQuery without any additional things


    A
    B
    C
    D
    E
    F
    G
    H
    I
    J
    K
    L
    1
    Source Result
    2
    Column1 Column2 Column3 Column4 Column5 Column6
    3
    a
    1
    6
    7
    8
    10
    1
    a c d
    4
    2
    c e
    5
    b
    3
    4
    9
    10
    3
    b c e
    6
    4
    b c d g
    7
    c
    1
    2
    3
    4
    5
    5
    c d f g
    8
    6
    a e f
    9
    d
    1
    4
    5
    8
    11
    7
    a f g
    10
    8
    a d g
    11
    e
    2
    3
    6
    9
    b
    12
    10
    a b f g
    13
    f
    5
    6
    7
    10
    11
    11
    d f
    14
    15
    g
    4
    5
    7
    8
    10
    Last edited by sandy666; 06-16-2018 at 02:39 PM.

  11. #11
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: How to sort and switch the data in the first column and the rest? (With an example)

    This problem was interesting enough to see if Sandy's answer could be improved on. I passed it on to Oz in Portland and see his answer in the link below.

    https://www.youtube.com/watch?v=Z0bN...ature=youtu.be

    I'm not sure I understand Pivot without Aggregate from Oz or pulling a list from a table from Sandy, but there are at least multiple ways to skin this cat.

+ 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-15-2013, 01:25 PM
  2. Select the last row in a column with data nd paste the value in the rest of the column
    By Sheldon Brooks in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-25-2013, 05:33 AM
  3. Replies: 1
    Last Post: 09-10-2012, 04:04 AM
  4. Replies: 4
    Last Post: 08-01-2012, 09:50 AM
  5. Replies: 2
    Last Post: 10-11-2011, 08:03 AM
  6. Replies: 1
    Last Post: 02-21-2011, 06:52 AM
  7. Switch Column Order with Data Already in Spreadsheet
    By ekrengel in forum Excel General
    Replies: 2
    Last Post: 08-28-2007, 10:10 AM
  8. [SOLVED] Thumbnail pictures in cells don't sort with rest of row
    By Don in forum Excel General
    Replies: 3
    Last Post: 02-26-2005, 10:06 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