+ Reply to Thread
Results 1 to 11 of 11

CONCAT/TEXTJOIN on Variable Number of Cells

  1. #1
    Registered User
    Join Date
    07-12-2006
    Location
    Ohio
    MS-Off Ver
    Newest
    Posts
    49

    CONCAT/TEXTJOIN on Variable Number of Cells

    Hello!

    I have a spreadsheet that looks something like this:
    Capture.JPG

    I've been trying to come up with a formula that I could paste down column B that will give me this:
    Capture2.JPG

    There's obviously many ways to do this when you've got 3 groups and 3-5 rows per group but I've got 200 groups (non-empty cells in column A) and they can have anywhere from 2 to 100 values in column C.

    I've tried to come up with a TEXTJOIN like TEXTJOIN(",",TRUE,C2:INDIRECT("C"&(2+COUNTBLANK(B2:B###)),TRUE).

    I think my problem is that I can't figure out how to count the number of empty cells between two non-empty cells without identifying which cells aren't empty by hand.

    Thanks for any help you can provide.

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: CONCAT/TEXTJOIN on Variable Number of Cells

    My first idea would be to write a macro. If the number of empty cells varies you'll need a way to find the row above the next non-empty cell but I wouldn't know how to do that with a formula, you could think of adding a helper column though
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Registered User
    Join Date
    07-12-2006
    Location
    Ohio
    MS-Off Ver
    Newest
    Posts
    49

    Re: CONCAT/TEXTJOIN on Variable Number of Cells

    Ya, a macro could definitely handle it. Trying to avoid it if I can.

    Was trying to think about a helper column. I was thinking of a MATCH() that gives a list of rows for where the formulas should start and stop. I can't get myself past that, though.

  4. #4
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: CONCAT/TEXTJOIN on Variable Number of Cells

    Attach a sample please,

  5. #5
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: CONCAT/TEXTJOIN on Variable Number of Cells

    Please try at B1 drag down

    =IF(A1="","",TEXTJOIN(",",,C1:INDEX(C2:C12,IFERROR(MATCH(1,INDEX(--(A2:A12<>""),),),MATCH(1,INDEX(--(C2:C12=""),),))-1)))

  6. #6
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: CONCAT/TEXTJOIN on Variable Number of Cells

    Another way, in B1

    =IF(A1="","",SUBSTITUTE(SUBSTITUTE(LEFT(TEXTJOIN(",",1,C1:C100),LEN(TEXTJOIN(",",1,C1:C100))-LEN(TEXTJOIN(",",1,B2:B101)))&",,",",,,",""),",,",""))

    The number of rows in each of the 3 ranges would need to be, at minimum equal to the number of rows in the largest group. Note that the last range (column B) starts and ends 1 row below the other ranges. The start cell of this range should be directly below the cell that the formula is entered into.

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

    Re: CONCAT/TEXTJOIN on Variable Number of Cells

    Hi,

    In reality, are the entries in column A numeric or text?

    Can two or more consecutive entries in column A be non-blank? For example, is this possible:

    A
    B
    C
    1
    111111
    Red
    2
    222222
    Yellow
    3
    Blue
    4
    333333
    Red

    ?

    Regards
    Click * below if this answer helped

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

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

    Re: CONCAT/TEXTJOIN on Variable Number of Cells

    Also, are the blank entries in column A 'genuine' blanks, or null strings ("") as a result of formulas within those cells?

    Regards

  9. #9
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: CONCAT/TEXTJOIN on Variable Number of Cells

    Just had another quick look at this to see if I could make my suggestion more efficient and came up with the following.

    Using a helper column, enter this into D1 and fill down

    =IF(OR(A1<>"",C2=""),ROW(D1),"")

    Then in B1 and fill down

    =IF(A1="","",TEXTJOIN(",",1,C1:INDEX(C:C,SMALL(D:D,COUNT(D$1:D1)+1)-1)))

    Noting XOR LX's questions above, both my original single column suggestion from post #6 and this one will work with any combination of those scenarios, Bo_Ry's suggestion from post #5 doesn't appear to work with consecutive non blanks.

  10. #10
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,718

    Re: CONCAT/TEXTJOIN on Variable Number of Cells

    If you are using a version of Excel that has TEXTJOIN, you might just as well use Power Query (Get & Transform) for this,
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  11. #11
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,718

    Re: CONCAT/TEXTJOIN on Variable Number of Cells

    Attached is a PQ solution.

    Excel 2016 (Windows) 32 bit
    A
    B
    C
    1
    Custom Custom.2 Column3
    2
    111111
    Red,Yellow,Blue Red
    3
    Yellow
    4
    Blue
    5
    222222
    Red,Orange,Yellow,Green,Blue Red
    6
    Orange
    7
    Yellow
    8
    Green
    9
    Blue
    10
    333333
    Red,Yellow,Green,Blue Red
    11
    Yellow
    12
    Green
    13
    Blue
    Sheet: Sheet2

    Here's the M code:

    Please Login or Register  to view this content.
    If this solution interests you and you'd like further advice, please shout.
    Attached Files Attached Files

+ 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. TEXTJOIN array for cells with functions in them (bug?)
    By Allerdrengen in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-02-2018, 05:24 AM
  2. [SOLVED] special formatting number within a concat function
    By jrtaylor in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-12-2018, 10:01 AM
  3. CONCAT formula for number format
    By Grayc16 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-09-2017, 03:19 PM
  4. trying to concat 2 cells in one DateTime value
    By acheo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-08-2016, 06:41 PM
  5. Replies: 3
    Last Post: 02-17-2015, 11:53 PM
  6. [SOLVED] Calculate average of variable number of cells variable number of times
    By WeirnetherlandsBart in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-06-2014, 10:11 AM
  7. Combine multiple cells in columns - Concat with variable spacing using VBA Script
    By AMC_CO in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-13-2013, 03:57 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