Results 1 to 7 of 7

Thread: concatenate across row 4. Use comma seperator.
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Mar 2002
    Posts
    416
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default concatenate across row 4. Use comma seperator.

    Hi ,

    I have values across row 4 from col A to Col AA that I have to concatenate and separate by commas.

    I believe I saw a third party solution with a custom MConcat or something like that.

    Can someone advise best way to concatenate without typing out A4&","&B4 etc...

    Thanks

  2. #2
    MrExcel MVP Rick Rothstein's Avatar
    Join Date
    Apr 2011
    Location
    New Jersey, USA
    Posts
    35,247
    Post Thanks / Like
    Mentioned
    92 Post(s)
    Tagged
    33 Thread(s)

    Default Re: concatenate across row 4. Use comma seperator.

    What version of Excel are you using?
    Rick's "mini" blog... http://www.excelfox.com/forum/f22/
    .
    Want to post a small screen shot? See Part B here.

  3. #3
    MrExcel MVP
    Junior Admin
    Joe4's Avatar
    Join Date
    Aug 2002
    Posts
    50,794
    Post Thanks / Like
    Mentioned
    57 Post(s)
    Tagged
    11 Thread(s)

    Default Re: concatenate across row 4. Use comma seperator.

    I think some of the newer versions of Excel have a built-in function that will do this (at the moment, I cannot recall the name of the function).
    If you do not have that, you can create a User Defined Function in VBA to do it.

    The function would look something like this:
    Code:
    Function MyConcat(rng As Range, delim As String) As String
    
        Application.Volatile
    
        Dim cell As Range
        Dim tmp As String
        
        For Each cell In rng
            tmp = tmp & cell & delim
        Next cell
        
        MyConcat = Left(tmp, Len(tmp) - Len(delim))
        
    End Function
    Then, you could access and use it like any other function in Excel, i.e. type this in your cell:
    Code:
    =MyConcat(A4:AA4,",")
    The first argument is the range you want to apply it to.
    The second argument is the delimiter you wish to use, enclosed in double-quotes.
    Last edited by Joe4; Jul 12th, 2019 at 02:23 PM.
    TIPS FOR FINDING EXCEL SOLUTIONS
    1. Use the built-in Help that comes with Excel/Access
    2. Use the Search functionality on this board
    3. A lot of VBA code can be acquired by using the Macro Recorder.

    "Give a man a fish, feed him for a day. Teach a man to fish, feed him for life!"

  4. #4
    Board Regular
    Join Date
    Mar 2002
    Posts
    416
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: concatenate across row 4. Use comma seperator.

    xl 2013

  5. #5
    Board Regular
    Join Date
    Mar 2002
    Posts
    416
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: concatenate across row 4. Use comma seperator.

    I think the function is called textjoin. i use office2013 so dont have.

  6. #6
    MrExcel MVP
    Junior Admin
    Joe4's Avatar
    Join Date
    Aug 2002
    Posts
    50,794
    Post Thanks / Like
    Mentioned
    57 Post(s)
    Tagged
    11 Thread(s)

    Default Re: concatenate across row 4. Use comma seperator.

    I think the function is called textjoin. i use office2013 so dont have.
    So, did you try my soluton?
    TIPS FOR FINDING EXCEL SOLUTIONS
    1. Use the built-in Help that comes with Excel/Access
    2. Use the Search functionality on this board
    3. A lot of VBA code can be acquired by using the Macro Recorder.

    "Give a man a fish, feed him for a day. Teach a man to fish, feed him for life!"

  7. #7
    MrExcel MVP Rick Rothstein's Avatar
    Join Date
    Apr 2011
    Location
    New Jersey, USA
    Posts
    35,247
    Post Thanks / Like
    Mentioned
    92 Post(s)
    Tagged
    33 Thread(s)

    Default Re: concatenate across row 4. Use comma seperator.

    Quote Originally Posted by Joe4 View Post
    I think some of the newer versions of Excel have a built-in function that will do this (at the moment, I cannot recall the name of the function).
    I don't have a version with it either, but I am pretty sure the function's name is TEXTJOIN.



    Quote Originally Posted by Joe4 View Post
    The function would look something like this:
    Code:
    Function MyConcat(rng As Range, delim As String) As String
    
        Application.Volatile
    
        Dim cell As Range
        Dim tmp As String
        
        For Each cell In rng
            tmp = tmp & cell & delim
        Next cell
        
        MyConcat = Left(tmp, Len(tmp) - Len(delim))
        
    End Function
    Since the OP's range is always going to be across a single row, there is a simple UDF available for him to use...
    Code:
    Function ConcatRow(RowRange As Range, Delim As String) As String
      ConcatRow = Join(Application.Index(RowRange.Value, 1, 0), Delim)
    End Function
    Note that I changed the function name and first argument to reflect this restricted range condition. In case the OP needs it...

    HOW TO INSTALL UDFs
    ------------------------------------
    If you are new to UDFs, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. You can now use NameOfTheUDF just like it was a built-in Excel function. For example,

    =ConcatRow(A4:AA4,",")

    If you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.
    Last edited by Rick Rothstein; Jul 12th, 2019 at 02:48 PM.
    Rick's "mini" blog... http://www.excelfox.com/forum/f22/
    .
    Want to post a small screen shot? See Part B here.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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