No—Excel for Microsoft 365 does not automatically merge cells just because they contain the same value. You can merge a selected group manually with Home > Merge & Center, or use a VBA macro to merge adjacent repeats; for most data lists, keeping cells separate and visually grouping them is safer.
What Excel does—and does not—do automatically
Excel has built-in commands for merging cells, but they act on a range you select. They do not monitor a worksheet and merge new matching values as you enter or paste them. Conditional Formatting can highlight matching values, and tools such as Remove Duplicates can change a data list, but neither feature merges cells.
There is an important distinction between cells that have the same value and cells that are next to each other. If A2:A4 all contain “North,” they form one contiguous group that can be merged vertically. If A2 says “North,” A3 says “South,” and A4 says “North,” the two North cells are separate groups. A macro intended to group repeats should not merge across the intervening South row.
Excel’s ordinary merge command also does not search a sheet for matching labels. It combines the cells in a selected rectangular range, regardless of whether their contents match. That can produce a merged cell even when the selected cells contain different values, with the associated risk of losing content.
Merge a selected group manually
For a small, fixed group of adjacent cells, use the ribbon. Select the cells, open Home > Merge & Center, and choose the option that suits the layout. Merge & Center merges the cells and centers the remaining value; the dropdown also includes Merge Across, Merge Cells, and Unmerge Cells. Merge Across merges each selected row separately, rather than making one tall merged cell.
- Select the adjacent cells you want to combine, such as A2:A4.
- On the Home tab, open the dropdown beside Merge & Center.
- Choose Merge Cells if you want to merge without centering, or Merge & Center if centering is appropriate.
- Read any warning about discarded contents before confirming.
On Windows, Ctrl+1 opens Format Cells, where the Alignment tab contains a Merge cells checkbox. On Mac, use Command+1 to open Format Cells; the same Alignment setting is available in desktop Excel. Excel for the web has a Merge & Center command on Home, although it does not run VBA macros. Ribbon details can vary slightly with the window size and version.
Automatically merge adjacent repeats with VBA
If you repeat this task on a prepared report, a macro can merge consecutive matching, nonblank values in one selected column. The following example works down the selected range and makes a vertical merge only when two or more neighboring cells match. It skips empty cells, cells that display an empty string, and error values. The comparison uses the underlying values, not the formatting shown on screen.
Select only the data range in one column, with no existing merged cells, then open the Visual Basic Editor (Alt+F11 on Windows; Option+F11 on many Mac keyboards, sometimes with Fn). Choose Insert > Module and paste this code. Run the macro from Developer > Macros, or press Alt+F8 on Windows. On Mac, the macro dialog shortcut is commonly Option+F8; use the Developer tab if the keyboard shortcut is intercepted by macOS.
Sub MergeAdjacentEqualCells()
Dim target As Range
Dim ws As Worksheet
Dim startCell As Range
Dim nextCell As Range
Dim firstRow As Long
Dim lastRow As Long
Dim runStart As Long
Dim r As Long
Dim oldAlerts As Boolean
If TypeName(Selection) <> "Range" Then Exit Sub
Set target = Selection
If target.Areas.Count <> 1 Or target.Columns.Count <> 1 Then
MsgBox "Select one continuous range in a single column."
Exit Sub
End If
Set ws = target.Worksheet
firstRow = target.Row
lastRow = target.Row + target.Rows.Count - 1
oldAlerts = Application.DisplayAlerts
On Error GoTo CleanFail
Application.DisplayAlerts = False
r = firstRow
Do While r <= lastRow
Set startCell = ws.Cells(r, target.Column)
If IsError(startCell.Value2) Then
r = r + 1
ElseIf Len(CStr(startCell.Value2)) = 0 Then
r = r + 1
Else
runStart = r
Do While r < lastRow
Set nextCell = ws.Cells(r + 1, target.Column)
If IsError(nextCell.Value2) Then Exit Do
If Len(CStr(nextCell.Value2)) = 0 Then Exit Do
If nextCell.Value2 <> startCell.Value2 Then Exit Do
r = r + 1
Loop
If r > runStart Then
ws.Range(ws.Cells(runStart, target.Column), _
ws.Cells(r, target.Column)).Merge
End If
r = r + 1
End If
Loop
CleanExit:
Application.DisplayAlerts = oldAlerts
Exit Sub
CleanFail:
MsgBox "Macro stopped: " & Err.Description, vbExclamation
Resume CleanExit
End Sub
Save a copy of the workbook before running a macro: merging changes the worksheet, and macros cannot be undone with Ctrl+Z. Save a workbook containing VBA as an Excel Macro-Enabled Workbook (.xlsm), and allow macros only when you trust the file. This code works on the selected column only; it does not search other columns, merge matching values separated by a different row, or create a live rule for future entries. If a sheet is protected or the range already contains merged cells, the operation may fail or need preparation first.
What counts as the same value?
Two cells can look identical without holding the same underlying value. For example, a cell formatted to show no decimal places might display 12 for both 12.2 and 12.4. A macro comparing values can treat those as different even though the displayed text matches. Likewise, two dates may appear in the same format but represent different dates or times internally.
The sample macro compares cell values returned by Excel, including the calculated results of formulas. If A2 and A3 contain different formulas that both return “North,” they qualify as a matching run, but merging keeps only the first cell’s content. Text comparison in the sample is case-sensitive under VBA’s default binary comparison: “North” and “NORTH” are treated as different. Spaces also matter, so “North” and “North ” are not identical values.
For a different rule, clean or standardize the source data before merging. For example, remove unwanted spaces in a helper column or normalize capitalization in a separate column, then review the results. Do not change the comparison logic casually: deciding that two entries are equivalent can affect which formulas or labels are discarded.
Risks and limitations of merged cells
A merged range stores its surviving content in the upper-left cell. If other cells in the selection contain data, Excel warns that merging keeps only the upper-left entry; the other contents are removed. Identical repeated labels may seem expendable, but cells can contain different formulas, comments, or values that are not obvious from their formatted appearance. Check the range before confirming, and keep a backup when the data matters.
Merged cells also make many routine worksheet operations less convenient. Sorting and filtering a list with merged cells can be restricted or produce confusing layouts. Copying, pasting, selecting ranges, filling formulas, and adjusting row heights can become harder because the merged area behaves as one larger cell. Merged cells are especially poor fits for source data that needs to be filtered, summarized with a PivotTable, or imported into another system.
Excel does not allow merging cells inside an Excel table. If the command is unavailable, check whether the selected cells are part of a table. Converting the table to a range may make merging possible, but it also removes table features such as automatic expansion and structured references. Do not convert a table solely to get merged labels if the table is still needed for analysis.
Safer ways to show repeated values as a group
If the goal is appearance rather than changing the data structure, use a presentation option that leaves every record intact. For a heading centered over several columns, select the cells and open Format Cells > Alignment. Choose Center Across Selection in the Horizontal list. This centers text across the selection without merging the cells. It is useful for headings, not a way to hide repeated values in a vertical list.
For a list with repeated category names, keep one value per row and use formatting to make groups easier to scan. Alternating row colors, borders at group boundaries, or Conditional Formatting can make transitions visible while preserving a normal rectangular data range. You can also sort by the category column so matching records appear together. If the requirement is a cleaner printed report, create a separate report or summary sheet rather than altering the underlying records.
Another common request is to display a label only once while leaving the other records available for calculations. You can leave the repeated source values intact and create a separate display column that shows a label at the start of each group. That approach requires a formula designed for the workbook’s layout, but it avoids deleting repeated records and keeps the original data usable. The right choice depends on whether the sheet is a presentation, a data source, or both.
Common problems and checks
If Merge & Center is unavailable, first check whether the selection is inside an Excel table, whether the worksheet is protected, and whether the selected area includes an incompatible existing merge. If a macro appears not to do anything, confirm that the selected range contains adjacent repeats: the code intentionally leaves single cells alone and does not merge identical values separated by a different value.
If the macro merges unexpected cells, undo is not available for macro changes. Close without saving if you have not made other changes you need, or restore the backup. Then inspect formulas, spaces, capitalization, and number formats in the source column. For a repeatable workflow, test the macro on a copied sheet with a small sample before applying it to a full report.
Frequently Asked Questions
Can Excel merge cells automatically when I type the same value?
No. Excel does not have a built-in setting that automatically merges cells when matching values are entered. A VBA macro can perform a merge when you run it, but it does not create an ongoing automatic rule unless you build and maintain a more complex event macro.
Can I merge cells that have the same value but are not next to each other?
Not into one ordinary merged range while preserving the rows between them. A merged range must be rectangular and contiguous. Sort or group the data first if the matching values need to sit together, and make a backup before changing the layout.
Will merging repeated values delete anything?
Excel retains the upper-left cell’s content and removes content from the other cells in the merged range. Even when the visible values match, formulas or underlying values may differ, so inspect the cells before merging.
Can I merge cells in Excel for the web?
Excel for the web provides merge options on the Home tab for selected cells. It does not run VBA macros, so use desktop Excel to run the macro shown above. Merged cells can still make sorting and editing less convenient in either environment.
What should I use instead of merging repeated labels?
Keep each row’s label intact if the range is a dataset. Use borders, shading, sorting, or a separate report layout to make groups clear. For a heading spanning columns, Center Across Selection can provide a centered appearance without combining cells.
Related
- Excel Date Format: Change Defaults and Cell Settings
- How to Change Date Format in an Excel Column Easily
- How to Change the Date Format in an Excel CSV File
Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.
More in How-to basics
- Excel Dropdown List From a Table Column That UpdatesYes. In Excel for Microsoft 365 on Windows, turn the source data into a table, define a workbook…
- How to Lock a Drop-Down List in ExcelTo protect a drop-down list in Excel, unlock the cells where people should make a selection, then use…
- Excel Max Cell Height: The 409-Point Row Height LimitIn Excel for Microsoft 365 on Windows, the maximum row height is 409 points, or about 5.68 inches…
- Schedule an Email in Outlook Desktop: Step-by-StepTo schedule an email in Outlook desktop, compose your message and choose a future send time: in new…
- Outlook Calendar Template: Create and Reuse EventsTo create a reusable calendar template, make an appointment in classic Outlook for Windows, then choose File >…
- How to Get Rid of a Page Split in ExcelTo remove a page split in Excel, first identify what you are seeing: for a print-page boundary, go…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.