LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default ColumnWidths, Characters & Pixels

Check out this link...

http://support.microsoft.com/default.aspx/kb/214123

--
HTH...

Jim Thomlinson


"Bart" wrote:

Dear all,

Adding Column Widths is somehow a very inaccurate matter. I tried to
measure the Width of 5 columns and make an other Column as wide as the
Widths of these 5 columns together. The column appeared to be less
wide.
It seems that the measurements aren't linear. Though I found out that
there's a relation between Characters and Pixels (Characters with the
Standard Font and Size).

m1 (Characters) | m2 (Pixels)
1 12
5 40
10 75
20 145
50 355
100 705

P = 7 * C + 5

P = number of Pixels
C = number of Characters

For example in my case I found the following measurements in
Characters (and Pixels):

2.86 (25 Pixels) +
15.86 (116 Pixels) +
15.86 (116 Pixels) +
15.86 (116 Pixels) +
12.29 (91 Pixels) +
20.14 (146 Pixels)
=82.87 Characters

The sum of these round figures is 82.87 Characters. (They are round
figures as they are when I read them as a Property of a Column.)
The sum of Pixels (not round figures) is 610.

Since the values of the ColumnWidth are round figures the calculation
isn't accurate (and so you might say non-linear). Calculating the
number of Characters with the number of Pixels by using the formula
stated above you get:

610 Pixels ‰¡ 86.43 Characters,

and not 82.87 Characters as stated above.

To work around this problem is by calculating in Pixels instead of
Characters. First convert the ColumnWidths to Pixels, do the
calculation and then convert it back to Characters. Like this e.g.:

Dim intPixels As Integer
Dim intTotalColumnWidth As Integer
Dim sngTotalColumnWidth As Single

For i = 1 To 3
intPixels = CInt(myRange.Columns(i).ColumnWidth * 7! + 5!)
intTotalColumnWidth = intTotalColumnWidth + intPixels
Next i

sngTotalColumnWidth = CSng(intTotalColumnWidth - 5) / 7!

myRange.Columns(1).ColumnWidth = sngTotalColumnWidth


Does someone have any other suggestions to obtain the ColumnWidth in
Pixels or calculate with ColumnWidths?

Bart


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ListWidth and ColumnWidths IT_roofer Excel Programming 0 July 31st 07 05:04 PM
Setting columnwidths Jason Zischke Excel Programming 5 July 1st 07 07:00 AM
ColumnWidths property Tom Excel Programming 4 April 11th 06 09:33 AM
some columns 30 characters 155 pixels others 310 pixels why vurden Excel Discussion (Misc queries) 2 April 26th 05 03:30 AM
listbox.Columnwidths question Stuart[_5_] Excel Programming 1 September 21st 03 07:26 PM


All times are GMT +1. The time now is 02:52 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"