+ Reply to Thread
Results 1 to 7 of 7

Concatenate multiple rows into one cell across multiple columns

  1. #1
    Registered User
    Join Date
    05-21-2020
    Location
    Illinois
    MS-Off Ver
    2016
    Posts
    3

    Concatenate multiple rows into one cell across multiple columns

    Hello!

    I have data by month for multiple plant species (Taxon column). There are 3 possible values for each month for each Taxon, and each value is shown on a separate row for each Taxon. I'd like to combine the rows so there is one row per taxon, and the values for each month are separated by a comma.

    The problem is best explained in the attached file. The OriginalData shows what I have to start with, and the DesiredResult tab is what the final calendar should look like.

    This is a small sample of the data, but I need to be able to do this repeatedly for multiple large data exports from Access. So, I'm looking for the easiest way to do this. Thank you!!
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,572

    Re: Concatenate multiple rows into one cell across multiple columns

    Hello rosiekangaroo and Welcome to Excel Forum.
    This proposal employs a helper table (columns O:AA) which may be moved and/or hidden for aesthetic purposes.
    Columns O:Z are populated using:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Column AA is populated using: =IF(A2<>A3,1,"")
    The final output, columns AC: is populated using:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Let us know if you have any questions.
    Attached Files Attached Files
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

  3. #3
    Registered User
    Join Date
    05-21-2020
    Location
    Illinois
    MS-Off Ver
    2016
    Posts
    3

    Re: Concatenate multiple rows into one cell across multiple columns

    That is amazing! Thank you so much. This worked great. It wasn't working perfectly for taxa with 3 rows, but I tweaked it so that the parts in wavy brackets was "Fl","M","Im","Fl, Im", to account for cells with the value "Fl, Im", and it works perfectly.

    In the second formula (columns AC:AO), is there a way the formula could be written so that it works automatically no matter how many rows of data are in the original list? In the example it was 18. I can change that number manually, and then drag the formula, and it works.

    Thanks again, you made my day! I would've never figured this out on my own.

  4. #4
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,572

    Re: Concatenate multiple rows into one cell across multiple columns

    I am glad that tweaking the first formula works well for your purposes.
    As to the second formula, it can be written with whole column references so as to accommodate all rows of data.
    AC2 and down: =IFERROR(INDEX(A:A,AGGREGATE(15,6,ROW($A:$A)/($AA:$AA=1),ROWS($A$1:$A1))),"")
    AD2:AO2 and down: =IFERROR(INDEX(O:O,AGGREGATE(15,6,ROW($A:$A)/($AA:$AA=1),ROWS($A$1:$A1))),"")
    Let us know if you have any questions.

  5. #5
    Registered User
    Join Date
    05-21-2020
    Location
    Illinois
    MS-Off Ver
    2016
    Posts
    3

    Re: Concatenate multiple rows into one cell across multiple columns

    Worked perfectly, thanks again!!!

  6. #6
    Registered User
    Join Date
    01-05-2020
    Location
    Texas
    MS-Off Ver
    O365 ProPlus
    Posts
    3

    Re: Concatenate multiple rows into one cell across multiple columns

    I grabbed the unique items in column A starting in row 21 on OriginalData using UNIQUE:

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


    Then, in cell B21, I put this:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    I copied down and across to be the same width as the original table.

    This works because if you compare a range with a value, you get an array that's the same length and width as the range you're comparing to the value, so this:

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


    creates an array of TRUE/FALSE, depending on whether the row in original data matches the row header on the new table. Passing a range of the same size to the THEN part of the IF means the returned array will have the text in that column if the IF part is TRUE. I concatenate the returned array with an empty string to make sure it doesn't return a zero where there's an empty cell:

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


    If the IF part returns FALSE, then just return an empty string.

    So, the IF returns a vertical array of the text in each row in that month's column, or an empty string if it doesn't match the row header in the new table. TRANSPOSE flips the array so it's horizontal, then TEXTJOIN joins each item in the array, separating them with a comma (first parameter in TEXTJOIN) and ignoring empty array items (second parameter).
    Attached Files Attached Files

  7. #7
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,572

    Re: Concatenate multiple rows into one cell across multiple columns

    You're Welcome and thank you for the feedback. Please take a moment to mark the thread as 'Solved' using the thread tools menu above your first post. I hope that you have a blessed day.

+ 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] Split Cell with multiple delimiters into multiple rows and columns
    By nobodyukno in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 07-03-2019, 04:43 PM
  2. Concatenate 2 rows but multiple columns - Is this possible?
    By Dan_B in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-20-2017, 07:13 AM
  3. Replies: 1
    Last Post: 08-19-2016, 07:03 AM
  4. How to Combine (Concatenate) Data from Multiple Rows into One Cell
    By syed82 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-02-2015, 04:38 AM
  5. [SOLVED] Concatenate Multiple Rows And Switch Columns If Blank
    By Knawl in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-17-2014, 05:11 AM
  6. Concatenate multiple rows and columns into 1 cell
    By mj44 in forum Excel General
    Replies: 19
    Last Post: 08-29-2013, 02:37 PM
  7. [SOLVED] How to Concatenate multiple Rows into 1 Column cell
    By rbapdx in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-11-2012, 12:02 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