columns width in a single vba statement

F

Fcoatis

Whats wrong with that?

Columns("A:E").Width = Application.Array(5, 10, 5, 10, 5)

Thanks in advance
 
G

GS

Whats wrong with that?
Columns("A:E").Width = Application.Array(5, 10, 5, 10, 5)

Thanks in advance

2 things I see right of are..
The Application object does not support an *Array* property (or
method);

Ranges do not have a *Width* property. Instead, they support
*ColumnWidth* and so your statement should read...

Columns("A:E").ColumnWidth = Array(5, 10, 5, 10, 5)

...but this is very slow to process (took about 1.5 minutes on my
machine) as a single statement. This will work orders of magnitude
faster (instantaneous) ...

Sub SetColWidths()
Dim vWidths, n&, j&
vWidths = Array(5, 10, 5, 10, 5)
With Range("A:E")
For n = 1 To .Columns.Count
.Columns(n).ColumnWidth = vWidths(j): j = j + 1
Next 'n
End With 'Range("A:E")
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 

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