How to Merge Cells in Excel: Step by Step Tutorial

Many people find it challenging to understand how to merge cells in Excel. At first, this may seem like a daunting task, but we've got your back! This blog will walk you through how to quickly merge cells in Excel.

IronXL: The C# Excel Library

IronXL is a C# Excel library with many advanced features for Excel operations. One main benefit of the IronXL C# library is that you don't need to install Excel software locally on your system. It processes the Excel document without using Excel software.

You can create a new Excel file and format data according to your needs using the IronXL C# library. It is a complete go-to package for all Excel operations. If you are building any software and have to create or edit an Excel file in your software, you can quickly perform such tasks with the help of the IronXL library. To use this library in your software build, you must download its DLL file or install it with NuGet Package Manager. You can use the free trial version to test all the features. The trial version is free, and it is very straightforward to use the license key with your project. You can also use this tutorial to better understand it. Once you are satisfied with IronXL, you can buy it at a very reasonable price.

Next, we will talk about how to merge cells in Excel using the IronXL C# library. IronXL provides elementary and easy-to-use functions to read and merge cells in an Excel file. Let's examine how to join cells in C# language using the IronXL library:

  1. Create a C# .NET or VB .NET project in Visual Studio.
  2. Download the DLL file of the IronXL library or install it via NuGet Package Manager in Visual Studio.
  3. Apply your License key using this tutorial.
  4. Use IronXL in your project.

    a. using IronXL;

  5. Load an Excel book using WorkBook.Load() static function.

    a. WorkBook wb = WorkBook.Load("fileaddress.xlsx");

  6. When the Excel file loads, select the sheet where we merge cells using the GetWorkSheet() function.

    a. WorkSheet ws = wb.GetWorkSheet("SheetName");

  7. We have selected the sheet where we have to merge cells. Let's choose the cell address to merge using the Merge() function.

    a. ws.Merge("FromCell:ToCell");

  8. Selected cells are merged, and now it's time to save the edited file using the SaveAs() function.

    a. wb.SaveAs("Filename.xlsx");

  9. You have now seen how easy it is to merge cells in Excel using the IronXL library, given a working knowledge of C#. You can also use the tutorials on Excel operations in the IronXL official documentation. Furthermore, IronXL also offers a wide range of features to interact with Excel WorkBook, WorkSheet and Cells level such as converting between popular formats, cell data formatting, merging cells, inserting math functions, and evenadding images.

You can download a zip file project that demonstrates how to merge cells.

Merging Cells in Microsoft Excel

Introduction to Microsoft Excel

Microsoft Excel is a spreadsheet application that helps users organize, analyze, and share data. It is one of the most popular office software programs to date. The goal of Excel is to simplify analyzing and managing data so people to be more productive at work. This particular tutorial will discuss how to merge cells in Excel. Before proceeding to examine how to join cells in Excel, you need to have a basic working knowledge of the following terms: cells and ranges.

What are Cells and Ranges in Excel

Cells

A cell is the smallest unit of data in a spreadsheet. This is where you enter data, formulas, and other information. Every spreadsheet has a grid made up of rows and columns, and every cell in the grid is assigned an address that uniquely identifies it on the grid. You can identify cells by their location in the grid, such as A1 or B3.

Ranges

A cell range is a group of cells with different addresses. For example, a cell range with two numbers must be formatted as A1:A5. In Excel, the default reference style is "Cells," which must be changed if you want to use a different one. There are two kinds of ranges: horizontal and vertical. Each type has its purpose and uses.

Methods of Merging Cells in Excel

Merging cells is essential because it saves time when working with large tables with many rows and columns. When merging cells, the software will automatically center on the merged cell so that there's no need to adjust it manually. When we merge cells, most upper-left cell values are retained. This will also make your table look nicer and easier to read. Let's look at how we can merge multiple cells in Excel.

1) Using the Merge & Center Button

How to Merge Cells in Excel: Step-by-Step Tutorial, Figure 1: Navigate to Merge Button in Excel Navigate to Merge Button in Excel

The Merge & Center button is the simplest method to merge cells in Excel. Let's examine how to merge cells using this method:

  • Open your Excel file in Microsoft Excel.

How to Merge Cells in Excel: Step-by-Step Tutorial, Figure 2: Excel File opened in Microsoft Excel Excel File opened in Microsoft Excel

  • Select the cells you want to merge.

How to Merge Cells in Excel: Step-by-Step Tutorial, Figure 3: Select two cells Select two cells

Now click on the Merge & Center button to merge selected cells.

How to Merge Cells in Excel: Step-by-Step Tutorial, Figure 4: Merge & Center button Merge & Center button

  • The cells will be merged. You will get this output:

How to Merge Cells in Excel: Step-by-Step Tutorial, Figure 5: Merged cell displayed in Microsoft Excel Merged cell displayed in Microsoft Excel

This method automatically merges cells and makes content aligned as centered. It is important to note that the software always preserves the furthest upper-left cell value. Other values will be discarded.

2) Merge cells using the "Format Cells" dialogue box

You can merge cells using the "Format Cells" dialogue box. This gives you multiple options. Let's examine how to merge cells using the "Format Cells" dialogue box:

Open your file in the Excel Software.

How to Merge Cells in Excel: Step-by-Step Tutorial, Figure 6: Excel File opened in Microsoft Excel Excel File opened in Microsoft Excel

Select the cells you want to merge.

How to Merge Cells in Excel: Step-by-Step Tutorial, Figure 7: Selecting cells Selecting cells

Open the "Format Cells" dialogue box. You can open it in various ways.

Go to the Home tab and click on the arrow icon on the Format button in the Cells section, and from the dropdown, select the Format Cells option.

How to Merge Cells in Excel: Step-by-Step Tutorial, Figure 8: Navigate to Format Cells button Navigate to Format Cells button

You can open the Format Cells dialogue box using the keyboard shortcut Ctrl + 1.

The third way to open this dialogue box is to right-click on selected cells and select the Format Cells menu.

How to Merge Cells in Excel: Step-by-Step Tutorial, Figure 9: Accessing Format Cells from right-click menu Accessing Format Cells from right-click menu

The Format Cells dialogue box will open. Go to the alignment tab, select merge cells, and click the OK button.

How to Merge Cells in Excel: Step-by-Step Tutorial, Figure 10: Format Cells dialog Format Cells dialog

Selected cells will be merged. You can identify merged cells by checking the borderlines of the cells.

How to Merge Cells in Excel: Step-by-Step Tutorial, Figure 11: Merged cell Merged cell

Notice that data in cells is not centered using this technique. This needs to be done manually from the home tab using the formatting section.

3) Alt Hot Key

You can perform this task quickly if you don't want to use your mouse, and instead use the keyboard to merge cells. You must select the cells you want to join and press Alt + H + M + C simultaneously. Your selected cells will be merged.

4) Quick Access Toolbar

If you want to use the merge tool frequently, you can add this option to your quick-access toolbar. Let's look at how we can add the Merge and Center option to the Quick Access toolbar.

Go to the title bar and click on the little arrow icon. It will show a dropdown. From the dropdown, select the More Commands option.

How to Merge Cells in Excel: Step-by-Step Tutorial, Figure 12: Navigate to More Commands Navigate to More Commands

A new pop-up box will open. Scroll down and select the Merge and Center option.

How to Merge Cells in Excel: Step-by-Step Tutorial, Figure 13: Excel Options UI Excel Options UI

After selecting Merge and Center, click the Add button, and this will add the command to the Quick Access toolbar options. Next, press OK to apply this change.

How to Merge Cells in Excel: Step-by-Step Tutorial, Figure 14: Adding Merge & Center button into the toolbar Adding Merge & Center button into the toolbar

Now, you can use the Merge and Center option using the Quick Access toolbar.

How to Merge Cells in Excel: Step-by-Step Tutorial, Figure 15: Quick Access toolbar UI Quick Access toolbar UI

You can use this button using Alt with another key. You can see which key is related to the Quick Access toolbar option by clicking the Alt key.

How to Merge Cells in Excel: Step-by-Step Tutorial, Figure 16: Quick Access toolbar UI with Shortcut key displayed Quick Access toolbar UI with Shortcut key displayed

You can use the Alt + 5 key combination to merge cells quickly.

5) Concatenate Function

If you wish to combine data from two or more columns, then the Merge and Center option will not work because it retains only the first cell's data and discards that from other cells. If you try to merge two or more cells that contain data, it will give you a warning as shown below:

How to Merge Cells in Excel: Step-by-Step Tutorial, Figure 17: Discard data dialog Discard data dialog

To combine the data from cells, you have to use an Excel function called the "Concatenate" function. Let's see how it works.

Let's say we want to combine a first name and a second name.

How to Merge Cells in Excel: Step-by-Step Tutorial, Figure 18: Data displayed before using concatenate Function Data displayed before using concatenate Function

We can't do it using the Merge and Center option. We will do it using the Concatenate function. Now move to the cell after the second name, where the data will be combined.

Type =Concatenate() and in parameters, give the address of those cells whose data you want to merge, like this:

How to Merge Cells in Excel: Step-by-Step Tutorial, Figure 19: Adding a new cell with concatenate function Adding a new cell with concatenate function

Press Enter, and you will see that the data from the two cells has been merged.

How to Merge Cells in Excel: Step-by-Step Tutorial, Figure 20: The result using Excel function The result using Excel function

Next, select the cell where the data is combined and dragged from the user to apply a function on other cells in the column.

How to Merge Cells in Excel: Step-by-Step Tutorial, Figure 21: Applying to multiple cells in the same column Applying to multiple cells in the same column

How to Merge Cells in Excel: Step-by-Step Tutorial, Figure 22: The final result The final result

You will see that the data from the two cells have been combined. You can now delete the columns if you don't want them.

Unmerge Cells

We can unmerge cells with a straightforward method:

  • Select the merged cells in Excel.
  • Go to the home tab and click on the Merge and Center button. It will unmerge cells.

This is how you can unmerge cells very quickly. If you wish to unmerge all merged cells in Excel, you can do it easily as follows:

  • Press Ctrl+A to select the whole sheet.
  • Go to the Home tab and select the Merge and Center button. It will unmerge all merged cells in an Excel sheet with just one click.