Log in
x
or
x
x
Register
x

or
0
0
0
s2sdefault

How to quickly merge adjacent rows with same data in Excel?

Supposing you have a worksheet with same data in the adjacent rows, and now you want to merge the same cells into one cell, so that the data looks neat and beautiful. (See following screenshots.) How do you merge adjacent rows with same data quickly and conveniently? Today, I will introduce you some quick way to solve this problem.

Merge adjacent rows of same data with VBA code

Merge adjacent rows of same data with Kutools for Excel


arrow blue right bubble Merge adjacent rows of same data with VBA code


Of course you can merge the same data with Merge & Center command, but if there are hundreds of cells need to be merged, this method will be time-consuming. So the following VBA code can help you merge the same data easily.

1. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications window.

2. Click Insert > Module, and paste the following macro in the Modulewindow.

Sub MergeSameCell()
'Updateby20131127
Dim Rng As Range, xCell As Range
Dim xRows As Integer
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Application.ScreenUpdating = False
Application.DisplayAlerts = False
xRows = WorkRng.Rows.Count
For Each Rng In WorkRng.Columns
    For i = 1 To xRows - 1
        For j = i + 1 To xRows
            If Rng.Cells(i, 1).Value <> Rng.Cells(j, 1).Value Then
                Exit For
            End If
        Next
        WorkRng.Parent.Range(Rng.Cells(i, 1), Rng.Cells(j - 1, 1)).Merge
        i = j - 1
    Next
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

3. Then press the F5 key to run this code, a dialog is displayed on the screen for selecting a range to work with. See screenshot:

doc-merge-same-data7

4. Then click OK, the same data in column A will be merged and centered. See screenshots:


arrow blue right bubble Merge adjacent rows of same data with Kutools for Excel

With the Merge same cells utility of Kutools for Excel, you can quickly merge the same values in multiple columns with one click.

Kutools for Excel includes more than 120 handy Excel tools. Free to try with no limitation in 30 days. Get it Now.

After installing Kutools for Excel, you can do as follows:

1. Select the columns that you want to merge the adjacent rows with same data.

2. Click Kutools > Range Converter > Merge Same Cells, see screenshot:

And the same data in the selected columns have been merged in one cell.

To know more about this, please visit this Merge Same Cells feature.


Related article:

Unmerge cells and fill with duplicate values in Excel


Recommended Productivity Tools

Office Tab

gold star1 Bring handy tabs to Excel and other Office software, just like Chrome, Firefox and new Internet Explorer.

Kutools for Excel

gold star1 Amazing! Increase your productivity in 5 minutes. Don't need any special skills, save two hours every day!

gold star1 200 New Features for Excel, Make Excel Much Easy and Powerful:

  • Merge Cell/Rows/Columns without Losing Data.
  • Combine and Consolidate Multiple Sheets and Workbooks.
  • Compare Ranges, Copy Multiple Ranges, Convert Text to Date, Unit and Currency Conversion.
  • Count by Colors, Paging Subtotals, Advanced Sort and Super Filter,
  • More Select/Insert/Delete/Text/Format/Link/Comment/Workbooks/Worksheets Tools...

Screen shot of Kutools for Excel

btn read more      btn download     btn purchase

Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Priya Mohan · 17 days ago
    Very helpful !! Thanks a lot
  • To post as a guest, your comment is unpublished.
    Joel · 3 months ago
    Can the VBA code be amended to achieve the same for merging across columns (as opposed to down rows, as above) and then repeat for all rows?
    • To post as a guest, your comment is unpublished.
      Punit · 2 months ago
      Use the above code and then transpose the result
  • To post as a guest, your comment is unpublished.
    anjana anand enginee · 4 months ago
    This was really helpful and has saved my time to greater extent
  • To post as a guest, your comment is unpublished.
    SUMAN PAUL · 6 months ago
    In EXCEL

    INPUT

    NAME PRO1 PRO2 PRO3
    A
    B
    C



    output

    A PRO1
    A PRO2
    A PRO3
    B PRO1
    B PRO2
    B PRO3
    C PRO1
    C PRO2
    C PRO3
  • To post as a guest, your comment is unpublished.
    Xandre · 1 years ago
    Hi,

    The makro works, but now when I want to filter on the column A, only the first Information from column B applicable to column A are seen.

    Looking at the example given in the makro, if I want to filter on Monday after the merge was done, only Nicol will Display and no info from Lucy and Lily are displayed.

    Is there a line I can add to avoid this?
    • To post as a guest, your comment is unpublished.
      punit · 2 months ago
      if you really want to filter then, merging the cells wont help you out.