Changing the Column Width or Row Height automatically to fit the contents is called AutoFit in Excel.
4 different methods to AutoFit Rows and Columns in Excel are explained in this blog post and the following is the data used for explaining these methods.
Table of Contents
AutoFit Rows and Columns manually
Select the entire Worksheet by clicking on the small triangle in the top left corner of the Worksheet.
Double-click on the border of any Column header to AutoFit Column Widths. Double-click on the border of any Row header to AutoFit Row Heights.
Note: Ctrl + A is the Keyboard shortcut to select the entire Worksheet.
Keyboard shortcut to AutoFit Rows and Columns
Alt + H + O + I is the Keyboard shortcut to AutoFit Column Width in Excel.
To AutoFit Row Height, press Alt + H + O + A
AutoFit Rows and Columns using the options in the Excel Ribbon
To AutoFit Columns,
select the data > in the Home tab of the Excel ribbon > Format > AutoFit Column Width
Similarly, select AutoFit Row Height to AutoFit Rows.
Macro to AutoFit Rows and Columns
The following code when executed will AutoFit the Rows and Columns of an Excel Worksheet.
Sub AutoFitRowsAndColumns() Cells.EntireColumn.AutoFit Cells.EntireRow.AutoFit End Sub