Skip to main content

How to join texts in a column without duplicates in Excel?

Do you know how to join texts from a column into a cell without duplicates in Excel? And what if join texts in a column without duplicates based on specific cell value? This article provides methods to solve the problems.

Join texts in a column without duplicates with formula
Join texts in a column without duplicates based on another cell value with VBA code
Easily join texts in a column based on another cell value with an amazing tool

More tutorial for combining cells…


Join texts in a column without duplicates with formula

As the below screenshot shown, you want to join texts in column A into a single cell without duplicates. Please do as follows.

1. Select a blank cell, copy the below formula into it and press the Alt + Shift + Enter keys at the same time.

=TEXTJOIN(", ", TRUE, IF(MATCH(A2:A12, A2:A12, 0)=MATCH(ROW(A2:A12), ROW(A2:A12)), A2:A12, ""))

Note: In the formula, “, ” is the separator of the combined texts; A2:A12 is the column cells you will join together. Please change them as you need.

Now the texts in specified column are joined without duplicates.


Join texts in a column without duplicates based on another cell value with VBA code

Sometimes, you may need join texts in a column without duplicates based on value in another cell, as below screenshot shown, you can get it down as follows.

1. In the worksheet contains the texts you will join, press the Alt + F11 keys to open the Microsoft Visual Basic for Applications window.

2. In the Microsoft Visual Basic for Applications window, click Insert > Module, and then copy the below VBA code into the Module code window.

VBA code: Join texts in a column without duplicates based on another cell value

Sub JoinTextsWithoutDuplicates()
'Updated by Extendoffice 20190924
    Dim xRg As Range
    Dim xArr As Variant
    Dim xCell As Range
    Dim xTxt As String
    Dim I As Long
    Dim xDic As Object
    Dim xValue
    Dim xStr, xStrValue As String
    Dim xB As Boolean
    On Error Resume Next
    xTxt = ActiveWindow.RangeSelection.Address
    Set xRg = Application.InputBox("Please select the data range", "Kutools for Excel", xTxt, , , , , 8)
    Set xRg = Application.Intersect(xRg, xRg.Worksheet.UsedRange)
    If xRg Is Nothing Then Exit Sub
    If xRg.Areas.Count > 1 Then
        MsgBox "Does not support multiple selections", , "Kutools for Excel"
        Exit Sub
    End If
    If xRg.Columns.Count <> 2 Then
        MsgBox "There must be only two columns in the selected range", , "Kutools for Excel"
        Exit Sub
    End If
    xArr = xRg
    Set xDic = CreateObject("Scripting.Dictionary")
    xDic.CompareMode = 1
    For I = 1 To UBound(xArr)
        If Not xDic.Exists(xArr(I, 1)) Then
            xDic.Item(xArr(I, 1)) = xDic.Count + 1
            xArr(xDic.Count, 1) = xArr(I, 1)
            xArr(xDic.Count, 2) = xArr(I, 2)
        Else
            xStrValue = xArr(I, 2)
           xB = True
            For Each xStr In Split(xArr(xDic.Item(xArr(I, 1)), 2), ",")
                If xStr = xStrValue Then
                    xB = False
                    Exit For
                End If
            Next
            If xB Then
            xArr(xDic.Item(xArr(I, 1)), 2) = xArr(xDic.Item(xArr(I, 1)), 2) & "," & xArr(I, 2)
            End If
        End If
    Next
    Sheets.Add.Cells(1).Resize(xDic.Count, 2).Value = xArr
End Sub

3. Press the F5 key to run the code. In the popping up Kutools for Excel dialog, select the range including both the values you will join texts based on and the texts you will join, and then click the OK button.

Then the unique values are extracted and their corresponding unique texts in another column are joined and placed in a new worksheet.


Easily join texts in a column based on another cell value with an amazing tool

Maybe you are not good at formula or VBA code. Here recommend the Advanced Combine Rows utility of Kutools for Excel for you. With this utility, you can easily join texts in a column based on value in another cell with only several clicks.

Before applying Kutools for Excel, please download and install it firstly.

Note: As the utility will directly apply in the original range, please make a copy of the original data before applying the below operation.

1. Select the range (include the texts you will join and the value you will join texts based on), click Kutools > Content > Advanced Combine Rows. See screenshot:

2. In the Advanced Combine Rows dialog, please do as follows:

  • Select the column containing the values you will join texts based on, and click Primary Key;
  • Select the column containing the texts you will join into a cell, and click Combine > Comma;
  • If there are columns left, please specify conditions for them. In this case, I select the Sales column and select Calculate > Sum.
  • Click the OK button. See screenshot:

Then you can see all the texts in specified column are joined based on the key column. See screenshot:

  If you want to have a free trial (30-day) of this utility, please click to download it, and then go to apply the operation according above steps.


Related articles

Combine duplicate rows and sum the values in Excel
In Excel, you may always meet this problem, when you have a range of data which contains some duplicate entries, and now you want to combine the duplicate data and sum the corresponding values in another column, how could you solve this problem? Try the methods in this article.

Combine Multiple Cells Into A Cell With Space, Commas or other separators In Excel
When you combine the cells from multiple columns or rows into a single cell, the combined data may be separated by nothing. But if you want to separate them with specified marks, such as space, commas, semicolon or others, how can you do? This tutorial will introduce some methods for you.

Concatenate cells keeping number/date formatting in Excel
You may have noticed that when we apply the CONCATENATE function in Excel, the date format (2014-01-03) and number format such as currency format ($734.7), percentage format (48.9%), decimal places (24.5000), etc. are removed and show as general numbers in the concatenation results. In this article we come up with several workarounds to concatenate data with keeping date or number formatting in Excel.

Reverse the concatenate function in Excel
As we all known, the Concatenate function in Excel can help us to combine multiple cells into one cell, but, sometimes, you want to do the opposite of Concatenate function, it means not combine cells, but split cell value into multiple separated cells. Methods in this article will help solve the problem.

Concatenate cells if same value exists in another column in Excel
This article provides methods to help you easily concatenate cells if same value existing in another column in Excel.

More tutorial for combining cells…

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...

Description


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
Comments (5)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
I like this formula, but often times i will have a blank cell in my data range and yet this formula won't work with blanks. how would i handle blank cells?
This comment was minimized by the moderator on the site
Thanks! This was helpful. I found that the formula below did the trick. I just needed to select a range to combine text, but didn't want to duplicate values.
=TEXTJOIN(", ",TRUE,UNIQUE($A2:$K2,TRUE))
This comment was minimized by the moderator on the site
This is a much easier way to join unique items based on another column:

=TEXTJOIN(", ",TRUE,UNIQUE(IF(Table1[Category]=Table2[Unique Categories],Table1[Items to Join],"")))

Works a treat, I use it a lot.
This comment was minimized by the moderator on the site
Thanks a Lot. You saved me.
This comment was minimized by the moderator on the site
Omg. You're a lifesaver, I was trying way more complex formulas and this worked like a charm! Thank you!
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations