![]() |
Column Width for Each Column
Hi Guys;
I have the code below working but I need to adjust the Column Width for Each Column Seperately! Only my second time with Excel, so please excuse my lack of experience! With ws.Range("A:Q").EntireColumn .ColumnWidth = 100 .AutoFit End With Example Column A = 25 Column B = 75 Column C = 14 etc. How do I do this in Macro Code? Thank You in Advance Group! Nancy X |
Column Width for Each Column
set up an array of columnwidths:
Dim myColWidths as variant dim iCol as long 'just 3 columns for my test mycolwidths = array(25, 75, 14) for icol = lbound(mycolwidths) to ubound(mycolwidths) 'same as for icol = 0 to 2 with ws.columns(icol+1) .columnwidth = 100 .autofit end with next icol Nancy X wrote: Hi Guys; I have the code below working but I need to adjust the Column Width for Each Column Seperately! Only my second time with Excel, so please excuse my lack of experience! With ws.Range("A:Q").EntireColumn .ColumnWidth = 100 .AutoFit End With Example Column A = 25 Column B = 75 Column C = 14 etc. How do I do this in Macro Code? Thank You in Advance Group! Nancy X -- Dave Peterson |
Column Width for Each Column
Sub MakeThemFitBetter() Dim vSizes As Variant Dim N As Long 'one number for each column width vSizes = Array(25, 75, 14, 19, 21, 23) 'need 17 numbers... For N = 1 To 17 ws.Columns(N).Width = vSizes(N - 1) Next End Sub -- Jim Cone San Francisco, USA http://www.realezsites.com/bus/primitivesoftware (Excel Add-ins / Excel Programming) "Nancy X" wrote in message Hi Guys; I have the code below working but I need to adjust the Column Width for Each Column Seperately! Only my second time with Excel, so please excuse my lack of experience! With ws.Range("A:Q").EntireColumn .ColumnWidth = 100 .AutoFit End With Example Column A = 25 Column B = 75 Column C = 14 etc. How do I do this in Macro Code? Thank You in Advance Group! Nancy X |
Column Width for Each Column
ws.Columns(N).Width = vSizes(N - 1) should read... Columns(N).ColumnWidth = vSizes(N - 1) -- Jim Cone "Jim Cone" wrote in message Sub MakeThemFitBetter() Dim vSizes As Variant Dim N As Long 'one number for each column width vSizes = Array(25, 75, 14, 19, 21, 23) 'need 17 numbers... For N = 1 To 17 ws.Columns(N).Width = vSizes(N - 1) Next End Sub -- Jim Cone San Francisco, USA http://www.realezsites.com/bus/primitivesoftware (Excel Add-ins / Excel Programming) |
All times are GMT +1. The time now is 07:24 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com