3 methods to concatenate rows into one cell based on group in Excel
Combining multiple rows of data into a single cell based on a group is a common requirement when working with structured datasets in Excel. For example, you may want to merge all names associated with the same class into one cell. This article provides step-by-step instructions using various methods and optimizations for different levels of expertise and use cases.
- Group and concatenate with formulas and Filter function
- Group and concatenate with Kutools for Excel easily
- Group and concatenate with VBA code
Group and concatenate with formulas and Filter function
You can use Excel's formulas along with the "Filter" function to concatenate rows based on one column. Please do as follows.
- In a new column, enter the following formula to concatenate the names and press "Enter". Drag down to apply it through the column range.
=IF(A2=A1,C1&", "&B2,B2)
- In a new column, enter the following formula, press "Enter" and drag down the formula.
=IF(A2<>A3,"Last","")
- Select all the data range including the helper columns. Select "Data" > "Filter" to add Filter icons to the data.
- Click the "Filter icon" in last helper column, only tick the "Last" checkbox, and click "OK".
Now the result is shown as below, you can remove the last helper column if you do not need it any more
Group and concatenate with Kutools for Excel easily
"Kutools for Excel" offers a simple and efficient solution - "Advanced Combine Rows", allowing you to merge grouped rows into a single cell with just a few clicks. It automatically adds custom separators such as commas, spaces, or line breaks to meet diverse data presentation needs.
Kutools for Excel - Packed with over 300 essential tools for Excel. Enjoy permanently free AI features! Download now!
- Highlight the cells that contain you data. Navigate to "Kutools" > "Merge & Split" > "Advanced Combine Rows".
- In the "Advanced Combine Rows" window, please configure as follow:
- Click the column which you want to combine rows based on, and set as "primary key".
- For the column you want to concatenate, such as the "Names" column in this case, specify a delimiter in the "Combine" section under the "Operation" field for this column.
- Click "OK" button.
Result: Kutools will automatically merge data based on the group into a single cell with specific delimiter.
Kutools for Excel - Supercharge Excel with over 300 essential tools. Enjoy permanently free AI features! Get It Now
Group and concatenate with VBA code
You can also use VBA to concatenate rows based on a group dynamically.
- Press "Alt" + "F11" keys to enable the "Microsoft Visual Basic for Applications" window.
- In the code editor, click "Tools" > "References" to enable "References" dialog, check "Microsoft Scripting Runtime" and save the changes.
- Go to "Insert" > "Module" and paste the following VBA code into the Module window. VBA: Concatenate rows into one cell based on group
Sub ConcatenateCellsIfSameValues() 'UpdatebyExtendoffice20180201 Dim I As Long Dim J As Long Dim xRg As Range Dim xRgKey As Range Dim xRgVal As Range Dim xStr As String Dim xDic As New Dictionary On Error Resume Next Set xRg = Application.InputBox("Select data range", "KuTools for Excel", Selection.Address, , , , , 8) If xRg Is Nothing Then Exit Sub Set xRgKey = Application.InputBox("Select key column", "KuTools for Excel", xRg.Columns(1).Address, , , , , 8) If xRgKey Is Nothing Then MsgBox "Key column cannot be empty", vbInformation, "KuTools for Excel" End If Set xRgVal = xRg(1).Offset(, 1).Resize(xRg.Rows.Count, xRg.Columns.Count - 1) For I = 1 To xRgKey.Count If I > xRgKey.Count Then Exit For xStr = "" For J = 1 To xRgVal.Columns.Count xStr = xStr & " " & xRgVal(I, J) Next If xDic.Exists(xRgKey(I).Text) Then xDic(xRgKey(I).Text) = xDic(xRgKey(I).Text) & xStr xRgKey(I).EntireRow.Delete I = I - 1 Else xDic.Add xRgKey(I).Text, xStr End If Next For I = 1 To xRgVal.Count xRgVal(I).Value = xDic(xRgKey(I).Text) Next End Sub
- Press the "F5" key to run the script. and follow any prompts to select your data range and specify key columns.
The result is shown as below:
When working with data in Excel, grouping and merging cells is a common yet complex task. Depending on your needs and tools, you can choose from several methods to achieve this goal. Select the most appropriate tool and method based on your specific needs and preferences to make your Excel work more efficient and convenient. If you're interested in exploring more Excel tips and tricks, our website offers thousands of tutorials to help you master Excel.
Demo: Group and concatenate with Advanced Combine Rows of Kutools for Excel
Best Office Productivity Tools
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...
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!
All Kutools add-ins. One installer
Kutools for Office suite bundles add-ins for Excel, Word, Outlook & PowerPoint plus Office Tab Pro, which is ideal for teams working across Office apps.





- All-in-one suite ā Excel, Word, Outlook & PowerPoint add-ins + Office Tab Pro
- One installer, one license ā set up in minutes (MSI-ready)
- Works better together ā streamlined productivity across Office apps
- 30-day full-featured trial ā no registration, no credit card
- Best value ā save vs buying individual add-in