When data is entered into a cell on your worksheet, should that cell not be wide enough to fit the data, it will cut off. You then have to resize the column manually. This can be excessive if your forms/macros are entering data into worksheets and you have to go through each one every time autofitting them.
In the VBA editor, open up the code window for any of the Worksheets, and paste this code:
[tt]Option Explicit
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Columns(Target.Column).AutoFit
End Sub
[/tt]
And that's it. Any data entered into that worksheet, be it manually or through a form/macro, will cause the columns to automatically expand/shrink to fit the longest entry.
N.B. Paste it into multiple Worksheet code windows, or into ThisWorkbook code window.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.