Edit: to do this 'automatically', after the initial autofit, for 'future' column widths that are exceeded will require a macro.
You are referring to autofitting the columns. To do this automatically will require a macro.
Copy the following macro to the clipboard:
Sub Autofit_Columns()
Dim ws As Worksheet
For Each ws In Worksheets
ws.Select
For Each col In ActiveSheet.UsedRange.Columns
col.AutoFit
Next
Next
End Sub
Press ALT + F11
In the menus at the top of the VBE, select INSERT > MODULE
Paste the macro into the editing area to the right.
Still in the VBE, go to Tools > Macros, select the macro, and click 'RUN'.
If there is the possibility that data added later might also exceed column widths, after performing the above process, do the following.
Copy this event handler to the clipboard:
Private Sub Workbook_SheetChange(ByVal Sh As Object, _
ByVal Target As Range)
ActiveSheet.Range(Target.Address). EntireColumn.AutoFit
End Sub
Press ALT + F11
Double click 'THIS WORKBOOK' in the Microsoft Excel Objects in the upper left quadrant.
Paste the code into the editing area to the right.
Close the VBE and return to the worksheet. Save the workbook.
Now, if data entered exceeds column width, autofit will be applied to the column when the user tabs to the next cell.
The one possible downside to autofitting is that if you have columns with very little data, the column width will be reduced to fit the data. That makes for some very narrow columns from time to time.