ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   columns width in a single vba statement (https://www.excelbanter.com/excel-programming/449693-columns-width-single-vba-statement.html)

Fcoatis

columns width in a single vba statement
 
Whats wrong with that?

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

Thanks in advance

GS[_2_]

columns width in a single vba statement
 
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



---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com


Fcoatis

columns width in a single vba statement
 
On Monday, January 13, 2014 12:04:09 PM UTC-2, Fcoatis wrote:
Whats wrong with that?



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



Thanks in advance


Thanks GS for the notes. Best Regards

GS[_2_]

columns width in a single vba statement
 
On Monday, January 13, 2014 12:04:09 PM UTC-2, Fcoatis wrote:
Whats wrong with that?



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



Thanks in advance


Thanks GS for the notes. Best Regards


You're welcome!

--
Garry

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



---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



All times are GMT +1. The time now is 07:23 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com