G
Gleam
I have a spreadsheet which has been created on another computer, and I am
having problems setting the column widths. My version of Excel 2003 is set to
use a default font size of 10. It appears that the computer the sheet was
created on, had a default font size of 12, because if I manually set the
column width to 10 and type in "1234567890" with a font size of 12 it fills
the column.
Having searched this forum I found a contribution from Nick HK and tried the
following code. On one of my spread sheets it worked fine - the message
returned 161.25, 161.25, 1.
When I ran it on the imported file it produced 207.75, 162.75, 1.27.
It has set the column width to 162.75 rather than the 161.25 I was expecting.
Is it possible to get it to set exactly? If not what margin of error can I
expect? In this example it is quite small but with some other code I was
getting 40.5 (aim) and 42 (actual) when using a factor derived from the
widest column (71.25) as the factor for a narrower column.
Sub test()
With Worksheets(1)
.Cells(5, 1).ColumnWidth = 30
Wpxl1 = .Columns(1).Width
factor = 161.25 / Wpxl1
.Cells(5, 1).ColumnWidth = 30 * factor
Wpxl2 = .Columns(1).Width
MsgBox Wpxl1 & ", " & Wpxl2 & ", " & Wpxl1 / Wpxl2
End With
End Sub
having problems setting the column widths. My version of Excel 2003 is set to
use a default font size of 10. It appears that the computer the sheet was
created on, had a default font size of 12, because if I manually set the
column width to 10 and type in "1234567890" with a font size of 12 it fills
the column.
Having searched this forum I found a contribution from Nick HK and tried the
following code. On one of my spread sheets it worked fine - the message
returned 161.25, 161.25, 1.
When I ran it on the imported file it produced 207.75, 162.75, 1.27.
It has set the column width to 162.75 rather than the 161.25 I was expecting.
Is it possible to get it to set exactly? If not what margin of error can I
expect? In this example it is quite small but with some other code I was
getting 40.5 (aim) and 42 (actual) when using a factor derived from the
widest column (71.25) as the factor for a narrower column.
Sub test()
With Worksheets(1)
.Cells(5, 1).ColumnWidth = 30
Wpxl1 = .Columns(1).Width
factor = 161.25 / Wpxl1
.Cells(5, 1).ColumnWidth = 30 * factor
Wpxl2 = .Columns(1).Width
MsgBox Wpxl1 & ", " & Wpxl2 & ", " & Wpxl1 / Wpxl2
End With
End Sub