Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Les Les is offline
external usenet poster
 
Posts: 240
Default Change width of 51 Columns

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Change width of 51 Columns

"Les" wrote in message
...
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


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



  #3   Report Post  
Posted to microsoft.public.excel.programming
Les Les is offline
external usenet poster
 
Posts: 240
Default Change width of 51 Columns

Hi Lorne,

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


"Lorne" wrote:

"Les" wrote in message
...
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


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




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Change width of 51 Columns

Range("A:H,K:P").Select
Selection.EntireColumn.AutoFit
--
Mike Q.


"Les" wrote:

Hi Lorne,

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


"Lorne" wrote:

"Les" wrote in message
...
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


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




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Change width of 51 Columns

don't know which columns, if they're consecutive or not, but you could possibly
use an array to store the widths.

--


Gary


"Les" wrote in message
...
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





  #6   Report Post  
Posted to microsoft.public.excel.programming
Les Les is offline
external usenet poster
 
Posts: 240
Default Change width of 51 Columns

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,
--
Les


"Gary Keramidas" wrote:

don't know which columns, if they're consecutive or not, but you could possibly
use an array to store the widths.

--


Gary


"Les" wrote in message
...
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




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Change width of 51 Columns

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


--


Gary


"Les" wrote in message
...
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,
--
Les


"Gary Keramidas" wrote:

don't know which columns, if they're consecutive or not, but you could
possibly
use an array to store the widths.

--


Gary


"Les" wrote in message
...
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






  #8   Report Post  
Posted to microsoft.public.excel.programming
Les Les is offline
external usenet poster
 
Posts: 240
Default Change width of 51 Columns

Thank you so much Gary.
In your opinion is this the best way to handle this ?
--
Les


"Gary Keramidas" wrote:

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


--


Gary


"Les" wrote in message
...
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,
--
Les


"Gary Keramidas" wrote:

don't know which columns, if they're consecutive or not, but you could
possibly
use an array to store the widths.

--


Gary


"Les" wrote in message
...
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






  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Change width of 51 Columns

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.

--


Gary


"Les" wrote in message
...
Thank you so much Gary.
In your opinion is this the best way to handle this ?
--
Les


"Gary Keramidas" wrote:

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


--


Gary


"Les" wrote in message
...
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,
--
Les


"Gary Keramidas" wrote:

don't know which columns, if they're consecutive or not, but you could
possibly
use an array to store the widths.

--


Gary


"Les" wrote in message
...
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








  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 367
Default Change width of 51 Columns

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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2007 How to change width of stacked columns bowfin Charts and Charting in Excel 4 April 4th 23 10:55 AM
How do I change the width of data columns in a column chart? Diana Charts and Charting in Excel 4 September 5th 07 05:26 PM
Change every 3 columns width with code Les Stout[_2_] Excel Programming 11 August 2nd 07 04:35 AM
Unwanted change in width of columns when showing formula. Erik Cardell New Users to Excel 2 April 11th 06 09:44 PM
columns change width Dave Excel Discussion (Misc queries) 0 May 14th 05 04:34 PM


All times are GMT +1. The time now is 09:05 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"