Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / November 2007

Tip: Looking for answers? Try searching our database.

Change width of 51 Columns

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Les - 15 Nov 2007 16:45 GMT
Hi all i am not a programmer but a dabbler and need help with changing the
widths of 51 columns, all variable in width.
What would be the best way to do this, it must be done by code ?
A lot of the columns are the same width, but spaced apart from each other..

Any help would be greatly appreciated
Signature

Les

Lorne - 15 Nov 2007 17:24 GMT
> Hi all i am not a programmer but a dabbler and need help with changing the
> widths of 51 columns, all variable in width.
[quoted text clipped - 3 lines]
>
> Any help would be greatly appreciated

The easiest way to do this is to go to the developer tab, turn on record
macro, change the width of a couple of columns, select some columns then
change their with, stop macro recording and press alt-F11 to look at what
was recorded.

In this case you get the code below from which you should be able to work
out how to do whatever it is you want to do with these articular column
widths:

Sub Macro1()
'
' Macro1 Macro
'
   Columns("D:D").ColumnWidth = 12.86
   Columns("G:G").ColumnWidth = 14.43
   Columns("J:M").Select
   Selection.ColumnWidth = 10.43
End Sub
Les - 15 Nov 2007 17:34 GMT
Hi Lorne,

I do know that method, thanks i just thought there might be an easer way
using an array... ?
Signature

Les

> > Hi all i am not a programmer but a dabbler and need help with changing the
> > widths of 51 columns, all variable in width.
[quoted text clipped - 23 lines]
> End Sub
>  
Mike Q. - 15 Nov 2007 18:24 GMT
Range("A:H,K:P").Select
Selection.EntireColumn.AutoFit
Signature

Mike Q.

> Hi Lorne,
>
[quoted text clipped - 28 lines]
> > End Sub
> >  
Gary Keramidas - 15 Nov 2007 20:58 GMT
don't know which columns, if they're consecutive or not, but you could possibly
use an array to store the widths.

Signature

Gary

> Hi all i am not a programmer but a dabbler and need help with changing the
> widths of 51 columns, all variable in width.
> What would be the best way to do this, it must be done by code ?
> A lot of the columns are the same width, but spaced apart from each other..
>
> Any help would be greatly appreciated
Les - 16 Nov 2007 06:32 GMT
Hi Gary, thanks for the reply that is what i had in mind. Could you help me
by showing me how one would do that Please.

Thanks in advance,
Signature

Les

> don't know which columns, if they're consecutive or not, but you could possibly
> use an array to store the widths.
[quoted text clipped - 5 lines]
> >
> > Any help would be greatly appreciated
Gary Keramidas - 16 Nov 2007 06:43 GMT
maybe something like this. this would set the width for the first 10 columns.
the option base 1 set the 1st element position to 1 instead of 0.

if you only had option explicit at the top, you have to use this line instead:
ws.Columns(i).ColumnWidth = arr(i - 1)

Option Base 1
Sub new_column_width()
     Dim i As Long
     Dim arr As Variant
     Dim ws As Worksheet

     arr = Array("25", "12", "8", "13", "9", "9", "12", "10", "12", "20")
     Set ws = Worksheets("Sheet1")

     For i = 1 To 10
           ws.Columns(i).ColumnWidth = arr(i)
     Next
End Sub

Signature

Gary

> Hi Gary, thanks for the reply that is what i had in mind. Could you help me
> by showing me how one would do that Please.
[quoted text clipped - 11 lines]
>> >
>> > Any help would be greatly appreciated
Les - 16 Nov 2007 06:51 GMT
Thank you so much Gary.
In your opinion is this the best way to handle this ?
Signature

Les

> maybe something like this. this would set the width for the first 10 columns.
> the option base 1 set the 1st element position to 1 instead of 0.
[quoted text clipped - 31 lines]
> >> >
> >> > Any help would be greatly appreciated
Gary Keramidas - 16 Nov 2007 06:58 GMT
i'm not qualified to answer that one. i know i've used this method before. maybe
someone who knows more than me will have an opinion.

Signature

Gary

> Thank you so much Gary.
> In your opinion is this the best way to handle this ?
[quoted text clipped - 37 lines]
>> >> >
>> >> > Any help would be greatly appreciated
carlo - 16 Nov 2007 08:29 GMT
Hi Les

you are talking about "the widhts are variable" but then you try to
use fixed widhts which are stored in an array.
Just to clarify the situation: Do those 51 Lines all have fixed widths
but all different widths, or do those widths vary depending on the
data?

in case 1)
you can use Garys answer

in case 2)
you should try the Autofit approach of Mike

Any other questions, just ask.

hth

Carlo
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.