ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Change column width (https://www.excelbanter.com/excel-programming/450757-change-column-width.html)

Robert Crandal[_3_]

Change column width
 
To change the column width of column "A", the following code
will work:

Columns("A:A").ColumnWidth = 1.57

Is it possible to reference each column with a numerical
index? Rather than using "A:A"?

I was hoping that the following code would work, but
it doesn't:

Columns(1,1).ColumnWidth = 1.57 ' wrong




Claus Busch

Change column width
 
Hi Robert,

Am Sat, 4 Apr 2015 02:36:09 -0700 schrieb Robert Crandal:

Is it possible to reference each column with a numerical
index? Rather than using "A:A"?


try:

Columns(1).ColumnWidth = 1.57


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional

Claus Busch

Change column width
 
Hi again,

Am Sat, 4 Apr 2015 11:43:58 +0200 schrieb Claus Busch:

Rather than using "A:A"?


it is not necessary to write
Columns("A:A")
Columns("A").columnwidth = 1.57
works also


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional

Robert Crandal[_3_]

Change column width
 
"Claus Busch" wrote:

Rather than using "A:A"?


it is not necessary to write
Columns("A:A")
Columns("A").columnwidth = 1.57
works also


Thanks again Claus.

BTW, I didn't want to use "A:A" or "A" because I am
using a for-next loop to change the width of multiple columns.
It just seemed easier with numerical references.

My code looks like this:

for i = 1 to 40
Columns(i).ColumnWidth = 1.57
next




Claus Busch

Change column width
 
Hi Robert,

Am Sat, 4 Apr 2015 03:04:01 -0700 schrieb Robert Crandal:

BTW, I didn't want to use "A:A" or "A" because I am
using a for-next loop to change the width of multiple columns.
It just seemed easier with numerical references.


you don't have to loop through the columns.
You can do it for a whole range:
Range("A1:AN1").ColumnWidth = 1.57
or:
ActiveSheet.UsedRange.ColumnWidth = 1.57


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional

Robert Crandal[_3_]

Change column width
 
"Claus Busch" wrote:

you don't have to loop through the columns.
You can do it for a whole range:
Range("A1:AN1").ColumnWidth = 1.57
or:
ActiveSheet.UsedRange.ColumnWidth = 1.57


Ah, even better! Thanks again.





All times are GMT +1. The time now is 01:28 AM.

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