cell width in vba - measurement unit

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
Hi
I want to change a cell width in vba. So I wrote the code below. I also went to option-->advance-->display-->ruler and change the unit to centimeters. I selected cell A1 and then went to home-->format-->cell width and it gave me 8.35.

My questions:
1) why excel did not show measurement unit when I went to home-->format-->cell width
2) when I change the width in my vba code to 20, what does 20 means here? cm or what? how can I make sure it is change to 20 cm in vba? Thank you

Code:
Sub col()
       ThisWorkbook.ActiveSheet.Columns(1).ColumnWidth = 20
End Sub

fyi chaning cell width/measurement unit article below

https://support.office.com/en-us/ar...w-height-72f5e3cc-994d-43e8-ae58-9774a0905f46
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
The default unit for columns is points.
As it's the default there is no need to identify it.
There are 28.3464567 Points in a centimetre.
so 20cm would be 566.929134 Points

Code:
Sub col()
       ThisWorkbook.ActiveSheet.Columns(1).ColumnWidth = 566.929134
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top