View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Gary Keramidas Gary Keramidas is offline
external usenet poster
 
Posts: 2,494
Default Column Width Problem

i'm sure there is a shorter way, but i have used something like this before.

Option Explicit
Sub set_column_widths()
Dim arr() As Double
Dim i As Long
Dim x As Long
Dim z As Long
x = 0
For i = 1 To 26
ReDim Preserve arr(0 To i - 1)
arr(x) = Worksheets("Sheet1").Columns(i).ColumnWidth
x = x + 1
Next

For x = LBound(arr) To UBound(arr)
Worksheets("Sheet2").Columns(x + 1).ColumnWidth = arr(x)
Next
End Sub
--


Gary


"Greg Lovern" wrote in message
oups.com...
I'm trying to copy column widths from a sheet in a workbook that is to
be supplied as needed by the user, to a sheet in a new workbook
created by my Excel macro. In the sample workbook supplied by the user
for development, I find that the destination column widths are
visually much narrower than the source column widths, though the
column width number is the same for both.

I understand that the meaning of column width units comes from the
normal font of the default style of the workbook. But again, in both
cases that's the same -- Arial 10pt. (In Excel 2003, I'm looking at
Format | Style | Normal | Font)

Of course, I've also made sure that zoom is the same for both too --
100%.

For now, I've worked around this problem by doing a copy on the
worksheet object into the new workbook, and deleting what I don't
want. That gives me the same column widths.

But I'd still like to know what could be causing the different column
widths I was seeing. Any suggestions?


Thanks,

Greg