How To Adjust row height of merged cells using VBA in Microsoft Excel?
Tags: toadjustrowheightofm, vbamacros
Published: 2021-10-08 01:52:29

---
title: How To Adjust row height of merged cells using VBA in Microsoft Excel?
published: true
date: 2021-10-07 07:01:35 UTC
tags: ToAdjustRowHeightOfM,VBAMacros
canonical_url: https://geekexcel.com/how-to-adjust-row-height-of-merged-cells-using-vba-in-microsoft-excel/
---

In this tutorial, we will guide you on how to **adjust the row height of merged cells using VBA** in Microsoft Excel. Let’s get them below!! Get an official version of MS Excel from the following link: **[https://www.microsoft.com/en-in/microsoft-365/excel](https://www.microsoft.com/en-in/microsoft-365/excel)**

## Example

- Firstly, in the Excel Worksheet, you have to go to the  **Developer Tab.**
- Then, you need to ** ** select the  **Visual Basic**  option under the  **Code**  section.

![Select Visual Basic](https://geekexcel.com/wp-content/uploads/2021/09/Select-Visual-Basic-9-1024x180.png)<figcaption>Select Visual Basic</figcaption>

- Now, you have to click on the  **Insert ** and select  **Module**.

![Insert a module](https://geekexcel.com/wp-content/uploads/2021/09/Insert-a-module.png)<figcaption>Insert a module</figcaption>

- After that, you have to  **copy and paste the code**  given below.

```
Sub AutoFitMergedCellRowHeight()
    Dim CurrentRowHeight As Single, MergedCellRgWidth As Single
    Dim CurrCell As Range
    Dim ActiveCellWidth As Single, PossNewRowHeight As Single
    If ActiveCell.MergeCells Then
      With ActiveCell.MergeArea
            If .Rows.Count = 1 And .WrapText = True Then
                Application.ScreenUpdating = False
                CurrentRowHeight = .RowHeight
                ActiveCellWidth = ActiveCell.ColumnWidth
                For Each CurrCell In Selection
                    MergedCellRgWidth = CurrCell.ColumnWidth + MergedCellRgWidth
                Next
                .MergeCells = False
                .Cells(1).ColumnWidth = MergedCellRgWidth
                .EntireRow.AutoFit
                PossNewRowHeight = .RowHeight
                .Cells(1).ColumnWidth = ActiveCellWidth
                .MergeCells = True
                .RowHeight = IIf(CurrentRowHeight > PossNewRowHeight, _
                  CurrentRowHeight, PossNewRowHeight)
            End If
        End With
    End If
Application.ScreenUpdating = True
End Sub

```

- You need to  **save the code**  by selecting it and then  **close the window**.

![](https://geekexcel.com/wp-content/uploads/2021/10/Save-the-Code-22-1024x643.png)<figcaption>Save the Code</figcaption>

- Again, you have to go to the  **Excel Spreadsheet** , and click on the  **Developer Tab**.
- Then, you need to choose the  **Macros option**  in the Code section.

![Choose Macro option](https://geekexcel.com/wp-content/uploads/2021/09/Choose-Macro-option-11-1024x184.png)<figcaption>Choose Macro option</figcaption>

- Now, you have to make sure that your  **macro name is selected**  and click the  **Run ** button.

![](https://geekexcel.com/wp-content/uploads/2021/10/Run-the-Code-21.png)<figcaption>Run the Code</figcaption>

- Finally, you will get the  **output ** as **adjusted row height of merged cells** in Excel.

## A Short Summary

Here, we have explained the step-by-step procedure on how to **adjust the row height of merged cells using VBA** in Microsoft Excel. Make use of this. Please share your worthwhile  **feedback**  in the below  **comment**  section. To learn more, check out our website **[Geek Excel](https://geekexcel.com/)!!**

**Keep Reading:**

- **[How to Change Row Height in Microsoft Excel 2007?](https://geekexcel.com/how-to-change-row-height-in-microsoft-excel-2007/)**
- **[Find and Select Merged Cells in Excel Office 365](https://geekexcel.com/how-to-find-and-select-merged-cells-in-excel-office-365/)**
- **[How to Change a Row Height in Microsoft Excel 365?](https://geekexcel.com/how-to-change-a-row-height-in-microsoft-excel-365/)**
- **[Set Row Height or Column Width in Inches/Pounds/Centimeters/Pixels!!](https://geekexcel.com/set-row-height-or-column-width-in-inches-pounds-centimeters-pixels/)**
- **[How to Filter Merged Cells in Microsoft Excel 365?](https://geekexcel.com/how-to-filter-merged-cells-in-microsoft-excel-365/)**