'How to adjust column width in Excel (.Width not .ColumnWidth)

When I use the code

ActiveSheet.Range("b:Az").ColumnWidth = 5
MsgBox ActiveSheet.Range("d1").ColumnWidth

it shows 5, but when using

ActiveSheet.Range("b:Az").ColumnWidth = 5
MsgBox ActiveSheet.Range("d1").Width

it shows 30

I know that the two properties are not the same (for some reason that I can't understand), but I want actually to adjust the property .Width not .ColumnWidth for some calculations in my code, but Excel refuses to adjust .Width property and shows Error '1004' (unable to adjust with property) when I run the following code:

ActiveSheet.Range("b:Az").Width = 5

so, how to adjust .Width property?



Solution 1:[1]

width can not be set -see here [https://docs.microsoft.com/en-us/office/vba/api/excel.range.width][1]

width gives you the width in pixel.

columnWidth can be set, according to ms-page: One unit of column width is equal to the width of one character in the Normal style

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Max