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…
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.
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.
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.
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: