As you type or enter data in a cell, its width does not change automatically. If you want the content to fit the cell, you have to resize the cell manually by double-clicking on the boundary line between the column or row headers. However, what if you want to automatically expand the cells to fit the content as you type? It eliminates the need for manual resizing and makes your Excel sheet look better organized and professional.
In this quick and simple tutorial, I will show the simplest way to automatically expand cells in Excel to fit the content. The best thing is, the method shown below works in all versions of Excel. i.e., Excel 97 and up (including Microsoft Excel 365). Let’s get started.
Enable Auto Fit Row & Column to Automatically Expand Cells
- Open the Excel file.
- Select the entire sheet by pressing the “Ctrl + A” shortcut.
- Navigate to the “Home” tab.
- Click the “Format” option under the “Cells” section.
- Select the “AutoFit Row Height” option to automatically adjust cell height.
- Select the “AutoFit Column Width” option to automatically adjust cell width.
- With that, all the cells in your Excel sheet will automatically expand as you type.
Use the VBA Command to Automatically Expand Cells in Excel
Excel has a built-in VBA command that makes the cells automatically expand and fit the content in it. Here’s how to use it.
- Open the Excel file.
- Right-click on the worksheet tab at the bottom.
- Select the “View code” option.
- Select “Worksheet” from the top dropdown menu.
- Enter the following commands between the first & last lines.
Cells.EntireColumn.AutoFit
Cells.EntireRow.AutoFit
- Close the VBA editor in Excel.
- That’s it, all the cells in your Excel sheet will automatically expand as you type.
Detailed Steps (With Screenshots)
First, open the Excel file in which you want autofit cells. Once it is opened, right-click on the worksheet tab and select the “View code” option to open the built-in VBA editor. As an alternative, you can also press the “Alt + F11” shortcut.
In the VBA editor window, select “Worksheet” from the first dropdown menu. This will apply the code to the entire worksheet. By default, it is set to “General”.
Now, copy and paste the below code between the first and last lines in the VBA editor.
Cells.EntireColumn.AutoFit
Cells.EntireRow.AutoFit
After typing the command, close the VBA editor (not the Excel sheet) and press “Ctrl + S” to save the changes.
That is all. From now on, all the cells in this worksheet will automatically resize according to the content in it.
Wrapping Up — Auto Resizing of Cells in Excel to Fit Content
As you can see, whether you use the format options or VBA code, auto-resizing the cells to fit content in an Excel file is fairly simple. If you are looking for a simple and easy approach, follow the first method. On the other hand, if don’t mind using VBA scripts then follow the second method. Whichever method you choose, it just works. Keep in mind that the changes only apply to this specific worksheet, if you open another Excel file, you have to reapply the settings if needed.
If you have any questions or need help, comment below. I’ll be happy to assist.