I'm trying the center the range from B:AE in the center of the screen by adjusting the width of column A.
I'm able to change the width by adding the width as number instead of using AdjColWidth
Sub TestWH()
'Get widths
WinWidth = ActiveWindow.UsableWidth
RangeWidth = ActiveSheet.Range("B1:AE1").Width
AdjColWidth = WinWidth - RangeWidth / 2
'If less than 4 then set to 4
If AdjColWidth < 4 Then
Range("A:A").ColumnWidth = 4
Else
Range("A:A").ColumnWidth = AdjColWidth
End If
End Sub
AdjColWidth
must be less than or equal to 255. I'm assuming your getting an error, and I'm assuming it isAdjColWidth
is greater than what is allowed.AdjColWidth = WinWidth - RangeWidth / 2
beAdjColWidth = (WinWidth - RangeWidth) / 2
? I mean I know there are limits, but on a 1080p screen a column nearly expands to the whole width at 100% zoom - the number produced by the second formula should be quite a bit smaller (but as you guys say you should check that it's less than 255 before setting it).Activewindow.UsableWidth
is in points, whereas one unit ofcolumnwidth
is equal to the width of one character in the Normal style