Here is a utility in Kutools for Excel, Advanced Combine Rows, which can combine rows or do calculations based on a key column in Excel. Click OK, now the result is shown as below: Click OK to select the key column you want to group based on.Ħ. Press F5 key, and select the data range you use in the popping dialog.ĥ. XDic(xRgKey(I).Text) = xDic(xRgKey(I).Text) & xStrĤ. MsgBox "Key column cannot be empty", vbInformation, "KuTools for Excel" Set xRgKey = Application.InputBox("Select key column", "KuTools for Excel", xRg.Columns(1).Address,, ,, , 8) Set xRg = Application.InputBox("Select data range", "KuTools for Excel", Selection.Address,, ,, , 8) VBA: Concatenate rows into one cell based on group Sub ConcatenateCellsIfSameValues()
How to concatenate rows in excel code#
Click OK, and click Insert > Module in VBA window, and copy and paste below VBA code to the Module script. Then in the window, click Tools > References to enable References dialog, and check Microsoft Scripting Runtime. Press Alt + F11 keys to enable the Microsoft Visual Basic for Applications window.Ģ. Here is a VBA code that also can handle this job.ġ. Now the result is shown as below, you can remove last helper column if you do not need it ever.
![how to concatenate rows in excel how to concatenate rows in excel](https://cdn.extendoffice.com/images/stories/doc-excel/doc-merge-columns-but-not-rows/doc-merge-columns-but-not-rows-4.png)
Click the Filter icon in last formula header, check Last checkbox only from the drop-down list, and click OK. Now select all the data range including formulas and click Data > Filter to add Filter icons to the data.Ĥ. Then in the next column, D13, type this formula =IF(A13A14,"Last",""), and drag fill handle down to apply the formula to cells you need.ģ. In the formula, A13 is the first data in the “Class” column, B13 is the first data in the “Name” column, “,” is the separator to delimit concatenate contents.Ģ.
![how to concatenate rows in excel how to concatenate rows in excel](https://pakaccountants.com/wp-content/uploads/2017/03/concatenate-text-in-excel-2.png)
In a blank cell next to the data range, for instance, C13, type this formula =IF(A13=A12,C12&", "&B13,B13), press Enter key and fill the formula to cells with dragging fill handle. Note: You need to sort your data by the class before following steps.ġ. In Excel, you can apply formulas to concatenated rows based on one column, then use the Filter function to display the result only. Group and concatenate with Advanced Combine Rows Group and concatenate with formulas and Filter function
![how to concatenate rows in excel how to concatenate rows in excel](https://i2.wp.com/itechguides.com/wp-content/uploads/2019/07/add-space-between-merged-cells-1024x677.png)
Now I want to concatenate the students in the same class into one cell as below screenshot shown, how can I quickly handle it in Excel? As you see, some students are in the same class, some are not. Here is a range of two columns, one is the class list, and the other is the student names list.
How to concatenate rows in excel how to#
How to concatenate rows into one cell based on group in Excel?