How to Use Autofit in Excel to Adjust Column Width and Row Height Automatically

How to Use Autofit Automatically

In addition to using autofit manually, you can also use autofit automatically. Automatic autofit is a feature that allows Excel to automatically adjust column width or row height whenever you add, change, or delete content in it.

To enable automatic autofit, you need to use VBA (Visual Basic for Applications), a programming language integrated with Excel. With VBA, you can create macros, which are a set of commands that Excel can execute automatically.

To create an auto autofit macro, you need to do as following steps:

  1. Open the Excel worksheet that you want to use automatic autofit.
  2. Press “Alt + F11” to open the “Visual Basic Editor”, which is the application used to create and edit VBA code.
  3. In the “Project Explorer” window, double-click on the name of the worksheet for which you want to use automatic autofit, for example “Sheet1”.
  4. In the “Code” window, type the following code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Target.EntireColumn.AutoFit
    Target.EntireRow.AutoFit
End Sub
  1. The above code means whenever there is a change in any cell in the worksheet, Excel will adjust the column width and row height automatically according to the size of the content contained in it.
  2. Press “Ctrl + S” to save the code.
  3. Close the “Visual Basic Editor” by pressing “Alt+Q”.

Now, you can try adding, changing, or deleting content in that worksheet, and see how Excel adjusts column width and row height automatically.

Conclusion

Autofit is a very useful and frequently used feature in Excel. Autofit lets you automatically adjust column width and row height according to the size of the content inside. By using autofit, you can make your table look neater and professional, without having to manually set column widths and row heights.

There are several ways to use autofit in Excel, either manually or automatically. Manually, you can use the mouse or ribbon menu to adjust the column width or row height automatically. Automatically, you can use VBA to create a macro that can adjust column width or row height automatically whenever you add, change, or delete content inside.

Thank you for reading this article. See you in the next article.

RELATED ARTICLES

Latest Articles