Your cart is currently empty!
How to Merge Adjacent Rows with Same Data in Excel
At Zenith Infotech, the HR department just released a new Internal Job Posting (IJP) list. Employees were buzzing with excitement — promotions, new roles, career growth! But when the Excel sheet was shared across departments, it looked… messy.
Here’s what it looked like:
Department | Name | Role |
---|---|---|
Sales | Radhika Rao | Executive |
Sales | Nikhil Jain | Associate |
Sales | Suresh Mehta | Manager |
IT | Neha Sinha | Developer |
IT | Ankit Verma | Tester |
Managers wanted a clean sheet — they wanted “Sales” and “IT” to appear merged across rows for easy viewing. That’s when Priya, a young MIS executive, was called in.
HR Head (Meena): “Priya, can we make this IJP sheet look more polished — like grouping departments by merged cells?”
Priya: “Absolutely, Ma’am. Excel loves a challenge!”
🧪 The Goal: Merge Adjacent Rows with the Same Data in Excel
We want the “Sales” cells to be merged down into one, the same with “IT”, but only if they are next to each other.
✅ Step-by-Step: Manually Merging Adjacent Cells with Same Values
- Sort the Data by the column you want to merge (e.g., Department).
- Go to
Data
→Sort
- Go to
- Select the range (e.g., A2:A6)
- Manually highlight the adjacent cells with the same value (like all “Sales”)
- Go to
Home
→ Click Merge & Center - Repeat for other repeated values.
🎯 This is easy and clean for small data sets, like Priya’s IJP sheet.
⚙️ But Priya Wanted Automation…
She used a VBA Macro to speed it up for 100s of rows.
🧾 VBA Code to Merge Adjacent Cells in Column A:
vbaCopyEditSub MergeSameCells()
Dim ws As Worksheet
Dim i As Long, lastRow As Long
Set ws = ActiveSheet
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
i = 2
While i <= lastRow
Dim startRow As Long: startRow = i
Do While i < lastRow And ws.Cells(i, 1).Value = ws.Cells(i + 1, 1).Value
i = i + 1
Loop
If i > startRow Then
ws.Range(ws.Cells(startRow, 1), ws.Cells(i, 1)).Merge
ws.Cells(startRow, 1).HorizontalAlignment = xlCenter
ws.Cells(startRow, 1).VerticalAlignment = xlCenter
End If
i = i + 1
Wend
End Sub
🔹 How to Use:
- Press
Alt + F11
to open VBA editor - Insert → Module → Paste the code
- Press
F5
to run - It will merge adjacent cells in Column A with same value.
🧠 Result?
Department (Merged) | Name | Role |
---|---|---|
Sales | Radhika Rao | Executive |
Nikhil Jain | Associate | |
Suresh Mehta | Manager | |
IT | Neha Sinha | Developer |
Ankit Verma | Tester |
Priya printed it and handed it to Meena.
Meena (smiling): “This looks like something made for the CEO’s desk. Great work, Priya!”
🧰 Bonus (No VBA): Use Excel Power Query
- Select data → Go to
Data
→From Table/Range
- Use Power Query to group by the column
- Expand details in the remaining columns
- Load data back to Excel
(Note: This doesn’t “merge” visually, but summarizes like a report)
📝 Summary:
- For small data → Use manual “Merge & Center”
- For many rows → Use a VBA Macro
- For structured grouping → Try Power Query
Top rated products
-
Mastering Tally ERP 9: The Complete Training Course
Original price was: ₹2,299.00.₹2,149.00Current price is: ₹2,149.00. -
Airtel Xstream Fiber: High-Speed Broadband
-
Mastering Microsoft Office: Excel, Access, Word, PowerPoint: Classroom/ Live Training
Original price was: ₹8,000.00.₹6,000.00Current price is: ₹6,000.00. -
Apple iPhone 17 (256GB Storage, Black)
-
MS Access Mastery Training in Hindi: Unleashing Data Potential
Original price was: ₹1,299.00.₹1,249.00Current price is: ₹1,249.00. -
Kama Ayurveda: Luxury Ayurvedic Skincare & Wellness