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.
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
-
Open Excel
Open the Excel workbook where you want to autofit columns.
-
Open the VBA Editor
Complete the following steps in the workbook:
- Press Alt + F11 on your keyboard to open the Visual Basic for Applications (VBA) editor.
- On the left side, right-click the sheet you want to modify and select View Code.
- From the top drop-down list, select Worksheet.
- Insert the code below inside the worksheet event procedure.
Private Sub Worksheet_SelectionChange(ByVal Target As Range) Cells.EntireColumn.AutoFit End SubCells.EntireColumn.AutoFitFinish: Close the Visual Basic editor and save your Excel file as .xlsm, the Excel Macro-Enabled Workbook format.