PC Review


Reply
Thread Tools Rate Thread

Column Width for Each Column

 
 
=?Utf-8?B?TmFuY3kgWA==?=
Guest
Posts: n/a
 
      20th Jul 2007
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
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      21st Jul 2007
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
 
Reply With Quote
 
Jim Cone
Guest
Posts: n/a
 
      21st Jul 2007

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" <(E-Mail Removed)>
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
 
Reply With Quote
 
Jim Cone
Guest
Posts: n/a
 
      21st Jul 2007

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


"Jim Cone"
<(E-Mail Removed)>
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)

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
cannot paste source column width to destination column width transkawa Microsoft Excel New Users 1 15th Oct 2010 04:09 PM
Create a macro which takes a column name and width and sets the column width to what it should be Ag Microsoft Excel Programming 4 29th Sep 2007 11:29 PM
setting Column width of Template Column in Datagrid.. Charleees Microsoft ASP .NET 2 20th Jun 2006 01:52 PM
Setting a column width of a Template column programatically =?Utf-8?B?Q29yZXlNYXM=?= Microsoft Dot NET 0 14th Mar 2005 03:15 PM
Re: How do I change the width of a column in an Excel column chart? Debra Dalgleish Microsoft Excel Charting 0 8th Sep 2004 10:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:45 AM.