Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA: Change Excel cell width

Tags:

excel

vba

I have some VBA and batch Scripts that read the Mac Address Table out of some switches and import it into Excel to format it.
But the text is too long for the default cell width.

Is it possible to change the displayed cell width?

(When saying displayed cell width I mean: this)

like image 825
Celestial Dragon of Osiris Avatar asked Mar 11 '14 10:03

Celestial Dragon of Osiris


2 Answers

Another method would be:

.Columns("A").ColumnWidth = 20 (or whatever value you need)

I didn't compare it speedwise but why my guess would be that it's more efficient to just use Columns() instead of Range().

For more info on the ColumnWidth-Value -> MSDN Doc for the columnwidth-property

like image 102
Smittie Avatar answered Oct 24 '22 03:10

Smittie


Use this:

Range("A1").ColumnWidth = ...

The units for this value are as following:

One unit of column width is equal to the width of one character in the Normal style. For proportional fonts, the width of the character 0 (zero) is used.

For example, the column width for freshly opened Excel file with default styles is 8.43 which is equal to 64 pixels.

...or this to autofit width:

Range("A1").EntireColumn.AutoFit
like image 40
ttaaoossuuuu Avatar answered Oct 24 '22 05:10

ttaaoossuuuu