+ Reply to Thread
Results 1 to 5 of 5

Merge multiple columns into single column based on ID

  1. #1
    Registered User
    Join Date
    03-28-2016
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    3

    Question Merge multiple columns into single column based on ID

    Hi there!

    I have a table similiar to that on the screenshot but with more than 10 000 rows.

    How can I combine multiple columns into single column based on ID without losing data?
    Attached sreenshot and file speak for themselves.

    example.png
    Attached Files Attached Files
    Last edited by sqlnoob; 03-28-2016 at 01:22 PM. Reason: solved

  2. #2
    Forum Expert ben_hensel's Avatar
    Join Date
    01-26-2012
    Location
    Northeast USA
    MS-Off Ver
    Office 365
    Posts
    2,043

    Re: Merge multiple columns into single column based on ID

    Multistep process:

    1) Rebuild the table using INDEX functions to grab all five supplier/supplier_code pairs and put on it's own row with ID code etc.
    I've attached a worksheet that shows how I did this. Note that you will have to change the references in the CEILING and MOD functions (plus their arithmetic modifiers) if the real data does not match the example data's five supplier/supplier_codes pairs, and how the data starts in row 4.

    2) Copy => Paste special (data only) either into a new field or over the top of that lookup table.
    Copy can be launched by CTRL+C or from the tooltip (right clicking on the selected cells).
    Paste Special can be launched from tooltip, you want the "Data Only" option under the Paste Options.

    3) Trim out the unwanted rows.
    Filter the table to hide all "Supplier" fields that are zeros. (These are fields that were blank without a supplier in the original data).
    Then you can delete those hidden rows by launching Document Inspector.
    Attached Files Attached Files
    Click the [* Add Reputation] Button to thank people for help!
    Post Attachment: Click [Go Advanced] under the reply box; then click [Manage Attachments] to launch the attachments dialogue.
    Mark Thread Solved: Go to the top of the first post; Select [Thread Tools] dropdown; Pick the [Mark thread as Solved] option.

  3. #3
    Registered User
    Join Date
    03-28-2016
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    3

    Re: Merge multiple columns into single column based on ID

    ben_hensel , thank you for your reply and time

    I'm yet to understand how it works - I'm trying to figure out the logic behind arithmetic calculations (in green).

    So if I have over 10k rows I need to make the following changes (in bold):

    =INDEX($E$4:$N$6;CEILING((ROW(D9)-10000)/5;1);(MOD(ROW(A9)-10001;5)*2)+1)

  4. #4
    Forum Expert ben_hensel's Avatar
    Join Date
    01-26-2012
    Location
    Northeast USA
    MS-Off Ver
    Office 365
    Posts
    2,043

    Re: Merge multiple columns into single column based on ID

    Those are not the correct changes. If you have five supplier rows across, you need the following instead:

    Please Login or Register  to view this content.
    This will take the row number of D9, subtract 8 (9-8 =1), divide by five (=0.2) and round up to the nearest integer (=1).

    Pull that down and you will see that this repeats each ID code 5 times.

    You will have to pull this down to row 50,000 or whatever to get it to repeat your 10,000 rows for five times.

    You can dropfill all the formulas after the first one though just by clicking the plus-sign when you hover over the bottom right corner of the cell, which will automatically pull down to the last row that has a value in it to the cell on the left.

    Please Login or Register  to view this content.
    Again, row A9 -8 =1, divide by 5, then take the modulus (the leftover after dividing); then multiply by two, and add one. This will displace the correct count over to get the right INDEX.

  5. #5
    Registered User
    Join Date
    03-28-2016
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    3

    Re: Merge multiple columns into single column based on ID

    You Sir are a beast!

    I'm so grateful! Thanks for this community and people like you!

    It works wonderfully!

+ 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. Merge specific column data from multiple sheets in single column of new workbook.
    By kadam203 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-14-2016, 01:58 AM
  2. Merge Multy Columns in Single column with data
    By sharma4845 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-22-2014, 05:02 AM
  3. Merge Multy Columns in Single column with data
    By sharma4845 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-22-2014, 05:00 AM
  4. [SOLVED] Sorting data into multiple columns based on a single column
    By J.McQ in forum Excel General
    Replies: 7
    Last Post: 03-16-2013, 11:26 AM
  5. MACRO to transform single column to multiple columns, based in dynamic values
    By gaqueiroz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-08-2012, 01:54 PM
  6. Transpose multiple text-based columns to single column while retaining record ids
    By SchoobsVT in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-06-2010, 12:26 PM
  7. merge data from multiple columns to single column
    By triggerthehorse in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-17-2005, 04:06 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