Autofit Data Automatically

How to autofit data automatically and wrap text in an Excel worksheet automatically with VBA. As we type data into an Excel worksheet we note that the content can be of different length and therefore we may need to auto-fit the content manually. To save time we can automate the complete process with a single line of code in VBA. The same applies to content that needs to be wrapped for better readability. Watch the video below:

Watch this video on YouTube.

Here’s the complete VBA code:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Range(“D3”).ColumnWidth = 20
Worksheets(“sheet1”).Range(“D3”).Value = “Total due in 15 days. Overdue accounts subject to a service charge of 1.5% per month.”
Worksheets(“sheet1”).Range(“D3”).WrapText = True

End Sub