How to Autofit Column Width in Excel (4 Methods)

Learn how to auto fit column widths in Excel with multiple methods including keyboard shortcuts and VBA automation. This guide covers the basics to advanced techniques and troubleshooting tips to help you work more efficiently in your spreadsheets.

Dynamic Date Example

by Mihir Kamdar / Last Updated:

how to autofit in excel

What You'll Learn

After reading this guide, you’ll be equipped with the knowledge to:

  • What is Autofit in Excel and why you need it.
  • Multiple ways to auto fit column widths, shortcuts and ribbon buttons.
  • How to use VBA code to auto fit when data changes.
  • Troubleshooting tips when autofit doesn’t work.

Download File

Download our step-by-step tutorial file now by clicking on the icon  download icon 1  below and follow along to enhance your Excel skills practically and efficiently!

Introduction

Working efficiently in spreadsheets is key to productivity. One of the common problems users face is adjusting column widths to show all the data. Manually resizing columns can take a long time especially with big datasets. The Excel Autofit feature is the quick fix by auto adjusting column widths to fit the data. Knowing how to use this feature will make your data more readable and workflow more efficient.

What is Column Autofit?

Autofit is an Excel feature that auto adjusts the width of columns (and the height of rows) to fit the cell content, ensuring the proper cell size. Excel cells expand automatically to fit the content using the Autofit feature, which can be accessed through the Excel ribbon. This way you don’t have to manually resize each column or row. Autofitting makes your spreadsheet look better and more professional and easier to read.

what-is-column-autofit-in-excel
Excel: Free Masterclass​
Supercharge Your Skills For Free

How to Auto Fit Column Width in Excel

There are several ways to auto fit column widths in Excel. Here are the methods:

Method 1: Double-Click Method

  1. Select Columns: Click on the column letter(s) you want to adjust. To select one column, click on its letter. To select multiple columns, click and drag across the column letters.

  2. Double-Click the Edge: Move your cursor to the right edge of any selected column header until it becomes a double arrow.

  3. Autofit: Double-click the edge. Excel will auto adjust the column width to fit the longest cell in each column.

how-to-autofit-column-in-excel-via-click
Excel: Free Masterclass​
Supercharge Your Skills For Free

Method 2: Ribbon Buttons and Double Click

  1. Select Columns: Highlight the columns you want to auto fit.
  2. Go to Home Tab: Go to the Home tab.
  3. Find Cells Group: Look for the Cells group.
  4. Click Format: Click the Format button.
  5. Choose Autofit Column Width: Select Autofit Column Width to automatically adjust the column width. This feature also works for adjusting the height of an Excel row, ensuring that all text fits within the cell without manual resizing.
  6.  
how-to-autofit-in-column-ribbon-button
Excel: Free Masterclass​
Supercharge Your Skills For Free

Method 3: Keyboard Shortcuts

Windows:

  1. Select the columns or one row you want to auto fit.

  2. Alt + H, O, I

how-to-autofit-column-in-excel-via-keyboard-shortcut
Excel: Free Masterclass​
Supercharge Your Skills For Free

Method 4: VBA to Auto Fit Columns

If you want columns to auto fit when data changes or need to adjust the height of multiple rows, you can use VBA (Visual Basic for Applications) to automate this. By writing an event driven macro, Excel can auto adjust column widths when you enter or change data in the worksheet.

Step by Step Guide to VBA:

Open the Visual Basic Editor (VBE):

  • Alt + F11 in Excel to open the VBE.

Go to Worksheet Module:

  • In the Project Explorer window (usually on the left side), find your workbook’s name.

  • Click Microsoft Excel Objects.

  • Double click on the sheet where you want the code to run (e.g. Sheet1).

Enter the VBA Code:

				
					Private Sub Worksheet_Change(ByVal Target As Range)

    On Error Resume Next
    Application.ScreenUpdating = False

    ' Adjust the column width of the column where the change occurred
    Target.EntireColumn.AutoFit

    Application.ScreenUpdating = True

End Sub

				
			

Paste the following code into the worksheet module:

  • This will auto fit the column width whenever a change is made in the worksheet.
  • Worksheet_Change event triggers every time a cell is changed.

 

Save Your Workbook as Macro-Enabled Workbook:

  • Go to File > Save As.
  • Choose Excel Macro-Enabled Workbook (*xlsm) from the file type dropdown.

 

Enable Macros When Opening the Workbook:

  • When you open the workbook, you may be prompted to enable macros. Click Enable Content to run the VBA code.

 

How the VBA Code Works:

  • Worksheet_Change Event: This event is triggered whenever any change is made to the worksheet.
  • Target: The range of cells that were changed.
  • Target.EntireColumn.AutoFit: Auto fits the entire column(s) of the cells that were changed.
  • Application.ScreenUpdating: Turned off to prevent screen flicker during the auto fit, then turned back on.
how-to-autofit-column-in-excel-via-VBA
Excel: Free Masterclass​
Supercharge Your Skills For Free

Tips for Better Spreadsheet Formatting

  • Wrap Text in Cells: If you have long text that you want to display within a fixed column width, wrap text to ensure proper row heights.
  • Select the cells and go to Home > Wrap Text.
  • Avoid Merging Cells: Merged cells can mess up auto fit and data sorting.
  • Use Tables: Convert your data range into an Excel Table for better data management.
  • Select your data and press Ctrl + T to create a table.
  • Set Default Column Width: Set default column width for new worksheets.
  • Go to Home > Format > Default Width.
tips for formatting column width

How to Auto fit Column Width in Excel?

To auto fit column width and row in Excel:

  • Method 1: Double click the right boundary of the column header.
  • Method 2: Select the column(s), go to Home > Format > Auto fit Column Width.
  • Method 3: Alt + H, then O, then I.

Why Auto fit Column Width Not Working for Multiple Columns?

Auto fit may not work because:

  • Merged Cells: Auto fit doesn’t work with merged cells.
  • Hidden or Filtered Cells: Hidden cells can affect auto fit calculation.
  • Cell Formatting: Cells with wrapped text or certain formatting may not auto fit as expected.
  • Manual Adjustments: If column widths are set to a fixed size, auto fit may not override them.
  • AutoFit Row Height: AutoFit Row Height may not adjust properly if there are multi-line texts or varying text sizes.

 

Solution:

  • Unmerge any merged cells in the column.
  • Make sure no filters are hiding data.
  • Check cell formatting and remove any that might be interfering.
  • Reset column width to default before auto fit.

Where is The Auto Fit Button in Excel?

The auto fit option is under the Home tab:

  • Go to Home tab.
  • In the Cells group, click on Format.
  • Select Auto fit Column Width or Auto fit Row Height from the dropdown. To adjust the height of multiple rows, select multiple rows by clicking and dragging over the row headers before choosing Auto fit Row Height.

Conclusion

Auto-fitting column width in Excel can be a game changer for your productivity and spreadsheet readability. Whether you’re manually auto-fitting columns or automating with VBA, these tips will help you present your data clearly and professionally without having to adjust manually all the time.

Facebook
X
LinkedIn
Pinterest
Email
Table of Contents

Office Tech Skill is a premier educational platform focused on Microsoft Office, providing professionals with the tools needed to thrive in the ever-evolving tech landscape.

© 2024 Office Tech Skill. All rights reserved