concatenate across row 4. Use comma seperator.

MikeL

Active Member
Joined
Mar 17, 2002
Messages
492
Office Version
  1. 365
Platform
  1. Windows
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
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
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:
Upvote 0
I think the function is called textjoin. i use office2013 so dont have.
 
Upvote 0
I think the function is called textjoin. i use office2013 so dont have.
So, did you try my soluton?
 
Upvote 0
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:
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,774
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top