Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Concatenating Ranges of Cells.

Concatenating Ranges of Cells

Written by Allen Wyatt (last updated September 12, 2019)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


3

Excel provides one workbook function and one operator that both have the same purpose—to combine strings into a longer string. The CONCATENATE function and the ampersand (&) operator have essentially the same purpose.

Many people use the ampersand operator in preference to the CONCATENATE function because it requires less typing, but CONCATENATE would become immensely more valuable if it would handle a range of cells. Unfortunately it does not, but you can create your own user-defined function that will concatenate every cell in a range very nicely. Consider the following macro:

Function Concat1(myRange As Range, Optional myDelimiter As String)
    Dim r As Range

    For Each r In myRange
        Concat1 = Concat1 & r & myDelimiter
    Next r
    If Len(myDelimiter) > 0 Then
        Concat1 = Left(Concat1, Len(Concat1) - Len(myDelimiter))
    End If
End Function

This function requires a range and provides for an optional delimiter. The last "If" statement removes the final trailing delimiter from the concatenated string. With the CONCAT1 function, cells can be added and deleted within the range, without the maintenance required by CONCATENATE or ampersand formulas. All you need to do is call the function in one of the following manners:

=CONCAT1(C8:E10)
=CONCAT1(C8:E10,"|")

The second method of calling the function uses the optional delimiter, which is inserted between each of the concatenated values from the range C8:E10. There is a problem with this, however: If a cell in that range is empty, then you can end up with two sequential delimiters. If you prefer to have only a single delimiter, then you need to make one small change to the function:

Function Concat2(myRange As Range, Optional myDelimiter As String)
    Dim r As Range

    For Each r In myRange
        If Len(r.Text) > 0 Then
            Concat2 = Concat2 & r & myDelimiter
        End If
    Next r
    If Len(myDelimiter) > 0 Then
        Concat2 = Left(Concat2, Len(Concat2) - Len(myDelimiter))
    End If
End Function

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (11247) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Concatenating Ranges of Cells.

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

Getting Rid of Extra Quote Marks in Exported Text Files

If you don't like the way that Excel exports information you intend to use with other programs, then your best bet is to ...

Discover More

Formatting Text Files with VBA

Got a bunch of text that you've imported from a text file? Need to make it look better? You can take a stab at it with ...

Discover More

Years in Which a Date Occurred on a Particular Day

If you need to know the years in which a particular date occurred on a specific day of the week, there are a number of ...

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)

Controlling Formula Reference Jumping

When you select a cell, you typically do so to see what the cell contains to to make changes to the cell. How Excel ...

Discover More

Automatically Adding 20% to an Entry

When you are developing a worksheet for others to use, you may want to have entries in a particular cell (or cells) be ...

Discover More

Getting Rid of All Rows Except the One for the Latest Date

As you use Excel to collect data over time, sometimes winnowing out the latest data can present a challenge. Here are a ...

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 two more than 7?

2023-11-21 17:05:56

J. Woolley

My Excel Toolbox includes the following function to combine values, arrays, and/or cell ranges into a delimited text string:
=JoinAsText(Delimiter,IgnoreEmpty,Values,...)
This function matches Excel 2019's TEXTJOIN. If Delimiter is a null string (""), the result is the same as CONCAT. For more, see my 2023-11-17 comment here: https://excelribbon.tips.net/T008663_Pulling_Initial_Letters_from_a_String.html
Also, see https://sites.google.com/view/MyExcelToolbox/


2019-09-12 09:18:32

Chuck Trese

A slightly more concise version of concat2:
(Instead of removing the extra delimiter at the end, it only adds the delimiter when it is needed.)

Public Function concat2(myRange As Range, Optional myDelimiter As String)
Dim r As Range

For Each r In myRange
If Len(concat2) > 0 And Len(r.Text) > 0 Then concat2 = concat2 & myDelimiter
concat2 = concat2 & r
Next r
End Function


2016-02-05 08:10:44

Paul Rowell

I made a couple of changes to Concat2:

Function Concat2(myRange As Range, Optional myDelimiter As String) As String

Dim r As Range

For Each r In myRange
If Len(r.Text) > 0 Then
Concat2 = Concat2 & r & myDelimiter
End If
Next r
If Len(myDelimiter) > 0 And Len(Concat2) > 0 Then
Concat2 = Left(Concat2, Len(Concat2) - Len(myDelimiter))
End If
End Function


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.