Skip to main content

Kutools for Office — One Suite. Five Tools. Get More Done.

How to auto fit row height of merged cells in Excel?

Author Xiaoyang Last modified

In Excel, adjusting row heights quickly and accurately is crucial for presenting your data clearly. Normally, you can use the AutoFit Row Height feature to automatically resize a row's height to fit its cell contents. However, when working with merged cells, you might notice that AutoFit Row Height does not respond as expected. That is, Excel's AutoFit function completely ignores merged cells, so you can’t automatically resize the row height to accommodate the content in these cases. As a result, you typically have to manually adjust the row height for each merged cell to ensure all the content is visible, which can be tedious and error-prone—especially when you have many merged cells.

This article introduces several practical methods to help auto fit the row height of merged cells effectively, saving you time and helping maintain a clean, readable worksheet:

Auto fit row height of merged cells with VBA code

Use Wrap Text and manual adjustment


Auto fit row height of merged cells with VBA code

Suppose your worksheet contains several merged cells with varying amounts of content, as shown in the screenshot below. If you want all your data to be fully visible without manually adjusting every row, you can use a VBA code solution to automatically fit the row height to the contents of each merged cell at once. This method is especially helpful when you have many merged ranges throughout your sheet, or when merged cell contents are frequently updated and you want to streamline the adjustment process.

Before running any VBA, remember to save your workbook as a macro-enabled file to prevent loss of unsaved work. VBA is a secure method provided by Excel, but ensure that macros are enabled and your security settings permit macro execution on your system.

sample data

1. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.

2. Click Insert > Module, then copy and paste the following code into the Module Window:

VBA code: Auto fit row height of multiple merged cells
Option Explicit
Public Sub AutoFitAll()
  Call AutoFitMergedCells(Range("a1:b2"))
   Call AutoFitMergedCells(Range("c4:d6"))
    Call AutoFitMergedCells(Range("e1:e3"))
End Sub
Public Sub AutoFitMergedCells(oRange As Range)
  Dim tHeight As Integer
  Dim iPtr As Integer
  Dim oldWidth As Single
  Dim oldZZWidth As Single
  Dim newWidth As Single
  Dim newHeight As Single
  With Sheets("Sheet4")
    oldWidth = 0
    For iPtr = 1 To oRange.Columns.Count
      oldWidth = oldWidth + .Cells(1, oRange.Column + iPtr - 1).ColumnWidth
    Next iPtr
    oldWidth = .Cells(1, oRange.Column).ColumnWidth + .Cells(1, oRange.Column + 1).ColumnWidth
    oRange.MergeCells = False
    newWidth = Len(.Cells(oRange.Row, oRange.Column).Value)
    oldZZWidth = .Range("ZZ1").ColumnWidth
    .Range("ZZ1") = Left(.Cells(oRange.Row, oRange.Column).Value, newWidth)
    .Range("ZZ1").WrapText = True
    .Columns("ZZ").ColumnWidth = oldWidth
    .Rows("1").EntireRow.AutoFit
    newHeight = .Rows("1").RowHeight / oRange.Rows.Count
    .Rows(CStr(oRange.Row) & ":" & CStr(oRange.Row + oRange.Rows.Count - 1)).RowHeight = newHeight
    oRange.MergeCells = True
    oRange.WrapText = True
    .Range("ZZ1").ClearContents
    .Range("ZZ1").ColumnWidth = oldZZWidth
  End With
End Sub

Notes:

(1.) If you need to adjust additional merged ranges, simply copy the line Call AutoFitMergedCells(Range("a1:b2")) as many times as required, and update the address for each merged range you wish to auto fit.

(2.) Remember to change Sheet4 in the script to match the worksheet name where your merged cells are located. If you're unsure of your worksheet name, check the sheet tabs at the bottom of your Excel window.

(3.) When running macros, ensure that no cells containing critical or sensitive data are inadvertently included in the selected ranges, to avoid unexpected formatting changes.

3. Press F5 to run this code. After execution, all specified merged cells will automatically adjust their row height to fully display the cell contents, as illustrated below:

 result of auto fitting row height of merged cells with vba code

This VBA solution provides a convenient, automated way to handle merged cell sizing. However, it requires access to the Developer tab and permission to use macros—keep this in mind if you’re collaborating in environments where macros are disabled or restricted.


Use Wrap Text and manual adjustment

For many scenarios, you can combine the Wrap Text feature with a quick manual row height adjustment to ensure all content is clearly visible without relying on VBA or complex tools.

Step 1: Enable Wrap Text
  1. Select the merged cell(s) you want to format.
  2. Go to the Home tab and click Wrap Text in the Alignment group.

This will allow the content to automatically wrap to new lines within the merged area.

Step 2: Check display and manually adjust row height if needed

If your text isn't very long, it may now fit perfectly inside the merged cell.

If the content is longer and still not fully visible, manually drag the row boundary below the merged cell to increase the row height until all content is displayed.

? Important note: Excel cannot auto-fit row height for merged cells automatically; the Wrap Text option only enables line breaks but does not auto-adjust row height. Therefore, you may need to manually tweak row height after wrapping the text.

Related article:

How to auto fit column width in Excel?


Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more
Use Kutools in your preferred language – supports English, Spanish, German, French, Chinese, and 40+ others!

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!

All Kutools add-ins. One installer

Kutools for Office suite bundles add-ins for Excel, Word, Outlook & PowerPoint plus Office Tab Pro, which is ideal for teams working across Office apps.

Excel Word Outlook Tabs PowerPoint
  • All-in-one suite — Excel, Word, Outlook & PowerPoint add-ins + Office Tab Pro
  • One installer, one license — set up in minutes (MSI-ready)
  • Works better together — streamlined productivity across Office apps
  • 30-day full-featured trial — no registration, no credit card
  • Best value — save vs buying individual add-in