View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Michel Pierron Michel Pierron is offline
external usenet poster
 
Posts: 214
Default Setting column width

Hi Brad,
Sub D_Adjust()
Dim R As Single, Unit As Single
Unit = Application.InchesToPoints(1)
Columns("B:C").EntireColumn.AutoFit
Columns("E:E").EntireColumn.AutoFit
R = Unit * 4
R = R - Columns(2).Width - Columns(3).Width - Columns(5).Width
Columns("D:D").EntireColumn.ColumnWidth = SetColWidth(R / Unit, 4)
End Sub

Function SetColWidth(ByVal R As Double, ByVal Col As Byte) As Double
Dim lr As Single
Application.ScreenUpdating = False
lr = Application.InchesToPoints(R)
While Columns(Col).Width lr
Columns(Col).ColumnWidth = Columns(Col).ColumnWidth - 0.1
Wend
While Columns(Col).Width < lr
Columns(Col).ColumnWidth = Columns(Col).ColumnWidth + 0.1
Wend
SetColWidth = Columns(Col).ColumnWidth
End Function

Regards,
MP

"Brad E." <Brad a écrit dans le message de
...
He everyone.

After entering text in columns B,C,E, I want to set the width of column D

so
that the sum of columns B:E = 4 inches (for printing purposes).

Right now I have this code:
Columns("B:C").EntireColumn.AutoFit
Columns("E").EntireColumn.AutoFit
TempCW = ActiveWindow.PointsToScreenPixelsX(Columns("B:C"). Width +
Columns("E:E").Width)
'Columns("D").ColumnWidth =
ActiveWindow.PointsToScreenPixelsX(Application.Inc hesToPoints(4) -
Round(TempCW))

Right now, column D ends up way too wide. I think I might be getting

mixed
up because there are inches, pixels, and .ColumnWidth (which doesn't equal
anything else).

NOTE: I remember seeing something in the help section about resolution.
This macro will be run on different computers with different resolutions.

One last thing. The firewall at work won't run Java, so I am submitting
this during my lunch hour at home. Could you e-mail any responses to me

at
work: .

Thanks, Brad E.