setting column width in Pixels with VBA

par60056

Well-known Member
Joined
Jul 26, 2012
Messages
1,581
Office Version
  1. 2011
  2. 2010
Platform
  1. Windows
  2. MacOS
Depending on where in the macro I have the line, the width of the column is different. I set columns(x).columnWidth=10.5. Depending on where I have the line it could be 69 pixels wide or 85 pixels wide. I know how many pixels wide I want it.

How can I set the column width to 85 pixels? If I know how to get how many pixels wide 1 width point was I could calculate it. But from what I read the width is dependent on the width of the characters in the font. There are multiple fonts in the column. So which one is it picking?
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
I understand that.

Now what happens if some of the cells in the column are Arial, some are Arial Narrow and some are 16pt, some are 12pt and some are 18pt? Which one does it choose? What effect does it have on how wide it is if some of the cells are merged to other columns to make a title bar?

If I set the width at the beginning will it choose to keep that many characters of the largest font/pointsize?

The 18pt title spans 5 columns. So I don't need that to go into the calculation of how wide any single column is. So I have the whole thing formatted with the fonts and sizes and I'm getting ##### in the numbers. I need to expand that column so the entire number displays and I can see I how many pixels it needs to be. Obviously I played with it and got it to the right size but I want to find an easier way than trial and error.
 
Upvote 0

Forum statistics

Threads
1,222,558
Messages
6,166,779
Members
452,070
Latest member
patbrunner2001

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