GET IN TOUCH: (213) 537 - 3054
610 S. Broadway Suite 1001 Los Angeles, CA 90014

Microsoft Excel  •  Knowledge Base

Use AutoFit to Adjust Cells in Excel

Keep worksheet content visible and organized by automatically adjusting column widths to match the data you enter.

FeatureExcel AutoFit
AutomationWorksheet VBA event
Save asMacro-enabled .xlsm

01

Why use AutoFit?

In Microsoft Excel, cell sizes do not always adjust automatically to fit the data you enter. This can cause text, numbers, or headings to appear cut off or hidden within a cell. The AutoFit feature solves this problem by automatically resizing rows or columns so that all the content is fully visible without manual adjustments. With just a few clicks, AutoFit ensures that your worksheet remains neat, organized, and easy to read.

Outcome: The worksheet column widths update to fit the content instead of requiring repeated manual resizing.

02

Configure the worksheet

  1. Open Excel

    Open the Excel workbook where you want to autofit columns.

  2. Open the VBA Editor

    Complete the following steps in the workbook:

    1. Press Alt + F11 on your keyboard to open the Visual Basic for Applications (VBA) editor.
    2. On the left side, right-click the sheet you want to modify and select View Code.
    3. From the top drop-down list, select Worksheet.
    4. Insert the code below inside the worksheet event procedure.
    Worksheet event
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        Cells.EntireColumn.AutoFit
    End Sub
    AutoFit statement
    Cells.EntireColumn.AutoFit

    Finish: Close the Visual Basic editor and save your Excel file as .xlsm, the Excel Macro-Enabled Workbook format.

TSC partner N-able partner