Excel Column autowidth
I am writing an application in VB 6 where I need to resize the column width of an Excel worksheet to that of the maximum size of the content in that column. The property Autofit only makes the width of the columns as wide as that of its caption. But I want it to be done on the basis of the maximum size of its content.
Is there a way to achieve this?
The autofit function should work fine, just make sure:
- First insert all data, the call autofit
- Call autofit on the entire column, not a single cell (e.g. .Cells(1,1).EntireColumn.Autofit()
Hope, this helps...
Your code should look something like this:
This example changes the width of columns A through I on Sheet1 to achieve the best fit:
This example changes the width of columns A through E on Sheet1 to achieve the best fit, based only on the contents of cells A1:E1:
Auto fit will work only for numbers and date.
- Enter your text
- place mouse on right top border of column heading
- when mouse pointer change
- then double click with control key
- your column width will be increase according to content....