Consulting

Results 1 to 7 of 7

Thread: Combine rows of data in to one cell

  1. #1

    Combine rows of data in to one cell

    I have a worksheet that contains a unique ID in column B. In column G there is other associated data. How do I combine the several rows of data in column G into one cell? Example of column B and G:

    1 ASDF
    1 SDF
    1 ADSF
    1 ASDF
    2 ASDF
    2 ASDF
    2 DFASDAS
    2 ASDF

    So I'd want all of the data associated with unique ID 1 in a single cell, but not in one long string.

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,873
    Assuming you have headers in row 1 and the data body starts in row 2, you can have a formula in a spare column (I used column I) in row 2 such as:
    =TEXTJOIN(" ",TRUE,IF($B$2:$B$9=B2,$G$2:$G$9,""))
    This formula is committed to the sheet with Ctrl+Shift+Enter, not just Enter.
    Then copy the formula down.
    Then you can copy/paste as Values the results of that formula, in situ, then do a remove duplicates operation using only columns B and I to find those duplicates.
    In the attached, I copied Sheet1 and did that (as well as deleting the data in column G).
    Attached Files Attached Files
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    Thank you very much! Any way to maintain the data so it's not one long string, e.g. end result in one cell would be:

    ASDF
    SDF
    ADSF
    ASDF

    Instead of
    ASDF SDF ADSF ASDF

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,873
    try:
    =TEXTJOIN(CHAR(10),TRUE,IF($B$2:$B$9=B2,$G$2:$G$9,""))
    Attached Files Attached Files
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  5. #5
    Thanks again for your help. When I try this i receive a #NAME? error. I've tried what was in the worksheet: =_xlfn.TEXTJOIN(CHAR(10),TRUE,IF($B$2:$B$9=B2,$G$2:$G$9,"")) as well as what you provided above: =TEXTJOIN(CHAR(10),TRUE,IF($B$2:$B$9=B2,$G$2:$G$9,""))

  6. #6
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,873
    It looks like you're working on a Mac or a version of Excel prior to Excel 2016?
    It's my bedtime here, so tomorrow sometime I'll cobble together a user-defined function to replace the missing TEXTJOIN function.
    I'll probably steal it from https://www.reddit.com/r/excelevator...ks_valuerange/ (you could use that yourself?)
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  7. #7
    I'm on Excel 2016. I put that function in and it works now. Thank you very much!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •