Ways to Concatenate Values

Written by Allen Wyatt (last updated August 19, 2022)
This tip applies to Excel 2007, 2010, 2013, and 2016


4

John noticed that Excel provides three ways to concatenate values: Using the & operator, the CONCATENATE function, and the new CONCAT function. He wonders about the differences between these various ways of putting together values and which is the best to use.

Actually, there is another new function (TEXTJOIN) which could also be used to concatenate values. This means that Excel now has four different ways to pull values together into a string.

Before explaining the differences, though, it may be best to define what is meant by "new" when, in this case, discussing "new functions." Specifically it means that the new functions are available to those using Excel 2016 if that version of Excel is based on an Office 365 subscription. This means that if you have Excel 2016 that is standalone, you won't have access to either CONCAT or TEXTJOIN. You only get them with the subscription. If you have an Office 365 subscription and you cannot use CONCAT or TEXTJOIN, you'll want to check for updates and make sure you are updated to the latest version—these two functions have been available since February 2016.

Now for the traditional methods of combining values: There is very little difference between using the & operator or the CONCATENATE function. The biggest theoretical difference is that the CONCATENATE function has a limit of 255 parameters that can be used with it, and the & operator does not. (I say "theoretical" because you've got to do a LOT of work to use 255 parameters with CONCATENATE.) Personally, I prefer to use the & operator for no other reason than it takes less time to type and is clearer to me than the function approach.

The CONCAT function does the traditional approaches one better, so to speak: It allows you to use ranges as parameters. This is actually pretty cool; consider the following usage:

=A1 & A2 & A3 & A4

Pretty straightforward, right? Well, with CONCAT you could simplify to this:

=CONCAT(A1:A4)

It becomes even better if you want to use a rectangular area. The old way is this:

=A1 & A2 & A3 & A4 & B1 & B2 & B3 & B4

Here's how to do it with CONCAT:

=CONCAT(A1:A4, B1:B4)

If you modified this a bit, you can easily combine the values by row within the range:

=CONCAT(A1:B4)

This is equivalent to the following:

=A1 & B1 & A2 & B2 & A3 & B3 & A4 & B4

Now, let's throw the TEXTJOIN function into the mix. This function adds two required parameters before the list of cells or ranges of cells you want to concatenate. These parameters allow you to add both a delimiter and indicate if empty cells should be ignored. Here's an example:

=TEXTJOIN(" ", TRUE, A1:B4)

In this usage, the function automatically adds a space character between each cell value that it concatenates. The delimiter isn't limited to a single character; you could use multiple characters. This sure beats the old way of doing it:

=A1 & " " & B1 & " " & A2 & " " & B2 & " " & A3 & " " & B3 & " " & A4 & " " & B4

The second TEXTJOIN parameter, set to TRUE in this example, indicates whether or not you want to skip blank cells in the ranges you are concatenating. This is really impossible to do with any other concatenation approach, and it makes the TEXTJOIN function very powerful. Plus, it gets rid of "double delimiters" as it truly only includes one delimiter between each value it adds to the resultant string.

Which of these four methods should you use to concatenate your values? It's up to you, but if you are developing workbooks that will be used by those with older versions of Excel, I'd suggest sticking to the & operator or the CONCATENATE function. If, however, you are pretty sure that those using the workbook will always have the latest version of Excel, then I'd blow right past CONCAT and use the TEXTJOIN function almost entirely.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (4629) applies to Microsoft Excel 2007, 2010, 2013, and 2016.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Word Graphics

One effective way to enhance your documents is with Word's powerful graphics capabilities. Discover how to best utilize ...

Discover More

Modified Rounding

Rounding is normally done so that values greater than or equal to .5 are rounded up and less than .5 are rounded down. ...

Discover More

Updating Many Template References

Documents rely on templates. If you change the location of those templates (on purpose or by accident), Word can take a ...

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

More ExcelTips (ribbon)

Making VLOOKUP Trigger a Macro

VLOOKUP is an oft-used worksheet function to lookup values in a data table. If the function cannot return a value, it ...

Discover More

Nesting IF Worksheet Functions

The IF worksheet function is very handy to make conditional evaluations. You are not limited to a single IF comparison, ...

Discover More

Calculating the Day of the Year

Need to know what day of the year a certain date is? You can figure it out easily using the formulas in this tip.

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is five more than 4?

2022-09-13 03:16:42

Thomas Papavasiliou

Another way is to place the text in a column and give a reasonable width to that column, using the built-in command "Fill > Justify".
This has some obvious limitations as the column width cannot exceed the given column width limits, but has the advantage of automatically adding a space,
If data is in rows, to put that in columns, the Copy > Paste Special > Transpose is a fast method.


2022-08-19 06:02:43

Kiwerry

Peter Atherton: Thanks for a practical function

I did notice one possible problem. In the following example
=cTEXTJOIN(";",TRUE,FALSE,A109:D109)
where cell C109 was empty, the result was
93;Excel;;Concatenating text
regardless of whether the second parameter (ignore_empty) was true or false.

The built-in function
=TEXTJOIN(";",TRUE,A109:D109)
returned
93;Excel;Concatenating text


2019-12-01 08:39:46

Peter Atherton

I missed pointing out that on the first example with the added text "England" this increaded the ayyay to two items, range, and array so LBound(Args) = 0 & UBound(Ags) = 1

Here is anoher based on the first example on the MS help page

(see Figure 1 below)

Figure 1. Text & Range


2019-12-01 08:27:49

Peter Atherton

You do not have the TEXTJOIN function if you have the Home version of Excel2016. I have tried to reproduce it in VBA. Here is the function, it has an extra variable to return the values in reverse positions.

Function cTEXTJOIN(Delimeter, ignore_empty, order As Integer, ParamArray Args() As Variant) As Variant
Dim i As Integer, tmpRng As Range, c As Range, n As Integer
Dim str As String, counter 'As Integer

For i = 0 To UBound(Args)
Select Case TypeName(Args(i))
Case "Range"
Set tmpRng = Intersect(Args(i).Parent.UsedRange, Args(i))
counter = UBound(Args()) '.Count)
If order = 0 Then
For Each c In tmpRng
n = tmpRng.Count
counter = counter + 1
If Not ignore_empty And Len(c) = 0 Then
str = str & Delimeter
ElseIf counter = n And Delimeter <> " " And i = UBound(Args()) Then
str = str & c
Else
str = str & c & Delimeter
End If
Next c
ElseIf order <> 0 Then
For Each c In tmpRng
n = tmpRng.Count
counter = counter + 1
If Not ignore_empty And Len(c) = 0 Then
str = Delimeter & c & str
ElseIf counter = n Then
str = c & str
Else
str = Delimeter & c & str
End If
Next c
End If
Case "String"
If i = UBound(Args) And order <> 0 Then
str = Args(i) & str
ElseIf i = UBound(Args) And order = 0 Then
str = str & Args(i)
Else
str = str & Args(i) & Delimeter
End If
Case Else
If i = UBound(Args) Then
str = str & Args(i)
Else
str = str & Args(i) & Delimeter
End If
End Select

Next i

cTEXTJOIN = str
End Function

It seems to work like the MS version
(see Figure 1 below)

Figure 1. 


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.