Column Width for Each Column

G

Guest

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
 
D

Dave Peterson

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
 
J

Jim Cone

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" <[email protected]>
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
 
J

Jim Cone

ws.Columns(N).Width = vSizes(N - 1)
should read...
Columns(N).ColumnWidth = vSizes(N - 1)
--
Jim Cone


"Jim Cone"
<[email protected]>
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top