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 + F11to open VBA editor - Insert → Module → Paste the code
- Press
F5to 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
-
Google Calendar Mastery Training: Learn to Streamline Your Schedule in Just 1 Hour
Original price was: ₹999.00.₹949.00Current price is: ₹949.00. -
Mark & Mia Woven Sleeveless Party Frock – Navy Blue
-
Mastering MS Excel (Pen Drive Course) – Learn Excel Anytime, Anywhere
Original price was: ₹4,999.00.₹1,299.00Current price is: ₹1,299.00. -
Best Ergonomic Gaming & Computer Chair
-
Casio MJ-12GST GST Calculator
-
Google Drive Mastery: Learn to Streamline Your Digital Workspace in 27 Minutes
Original price was: ₹999.00.₹949.00Current price is: ₹949.00.






