Formatting Issues

How to Merge Adjacent Excel Cells with Identical Values

Ayan MasoodAyan Masood Oct 29, 2026 870 views

Question details

The user wants to merge adjacent cells in Excel that contain the exact same values to clean up schedules, timetables, or reports.

How to Merge Adjacent Excel Cells with Identical Values
Product
Microsoft Excel
Device & OS
not provided
Scenario
Formatting schedules, timetables, or reports with repeated adjacent entries.
Observed behavior
Excel formulas cannot physically merge cells based on matching values, requiring alternative formatting or macro solutions.
Before you start

Before running any VBA macros to merge cells, ensure you create a backup copy of your workbook. Merging cells physically can permanently remove or alter existing cell content, and macro actions cannot always be undone.

Solution 1Recommended

Use a VBA Macro to Physically Merge Cells

Since Excel formulas cannot merge cells, a VBA macro is the most effective way to automatically detect and merge adjacent cells with identical values.

Using a VBA script allows you to automate the process of checking adjacent rows or columns for duplicate values and merging them instantly. This is highly efficient for large datasets like timetables or rosters.

1
Open the VBA Editor

Press Alt + F11 on your keyboard to open the Microsoft Visual Basic for Applications window.

2
Insert a New Module

Click 'Insert' in the top menu, then select 'Module' to create a new blank module window.

3
Paste the Merge Code

Paste a VBA script designed to loop through your selected range and merge cells with matching values. Ensure the script includes 'Application.DisplayAlerts = False' to prevent Excel from showing a warning prompt for every single merge.

4
Run the Macro

Close the VBA editor and return to your worksheet. Select the range of cells you want to process, press Alt + F8, select your newly created macro, and click 'Run'.

Use a VBA Macro to Physically Merge Cells
Data Loss Warning: When Excel merges cells, it only keeps the upper-left value and discards the rest. Ensure your data is backed up before running the macro.
Merge Cells Easily in WPS Spreadsheet

Manage and Format Data Effortlessly with WPS Office

WPS Spreadsheet offers powerful formatting tools, seamless VBA macro support, and intuitive cell merging features to help you organize schedules and reports without the hassle.

  1. 1. Open Your Workbook: Launch WPS Spreadsheet and open the file containing the data you need to merge.
  2. 2. Run a VBA Macro: Navigate to the 'Developer' tab, click 'Macros' or 'Visual Basic', and run your script to merge identical adjacent values.
  3. 3. Apply Conditional Formatting: Alternatively, select your cells, go to the 'Home' tab, and use 'Conditional Formatting' to hide duplicate values visually.
  4. 4. Use Manual Merge Tools: For smaller datasets, simply select the identical cells and click the 'Merge and Center' dropdown on the Home tab.
Fully compatible with Microsoft Excel formats (.xlsx, .xls, .csv, .xlsm).Robust support for VBA macros, allowing you to easily automate merging adjacent cells.Intuitive UI with quick access to Conditional Formatting and Merge & Center tools.Free, lightweight, and fast to install on Windows, Mac, and Linux.
microsoft office alternative - wps office

Frequently Asked Questions

Can I use an Excel formula to merge cells with the same value?

No, Excel formulas can only calculate and return values; they cannot change the physical structure or formatting of the worksheet, such as merging or unmerging cells. You must use VBA or manual merging tools.

Will I lose data when merging adjacent cells in Excel?

Yes. When you physically merge multiple cells in Excel, the system only retains the data from the upper-leftmost cell in the selection and deletes the data in the other merged cells.

How do I unmerge cells that were merged by a macro?

You can unmerge cells by selecting the merged block, going to the Home tab, and clicking the 'Merge & Center' button again to toggle it off. However, the data discarded during the original merge will not be restored.

Why is my VBA macro not running to merge the cells?

Your macro might be blocked by security settings. Go to File > Options > Trust Center > Trust Center Settings > Macro Settings, and ensure macros are enabled. Also, ensure your file is saved as a Macro-Enabled Workbook (.xlsm).