concatenate across row 4. Use comma seperator.

MikeL

Active Member
Joined
Mar 17, 2002
Messages
417
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
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
51,844
Office Version
365
Platform
Windows
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:

MikeL

Active Member
Joined
Mar 17, 2002
Messages
417
I think the function is called textjoin. i use office2013 so dont have.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
51,844
Office Version
365
Platform
Windows
I think the function is called textjoin. i use office2013 so dont have.
So, did you try my soluton?
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
35,575
Office Version
2010
Platform
Windows
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.



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:

Forum statistics

Threads
1,086,093
Messages
5,387,793
Members
402,076
Latest member
MotoMoto

Some videos you may like

This Week's Hot Topics

Top