Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default 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



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default 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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default 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
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default 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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default 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


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default 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.



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
Why can't i change column width? Carole S Excel Discussion (Misc queries) 4 April 4th 23 10:10 AM
Change Cell Width WITHOUT changing Column width dww701 Excel Discussion (Misc queries) 1 January 12th 09 10:52 PM
Change the column width Nikolaus Excel Discussion (Misc queries) 3 December 18th 08 08:36 PM
change column width Ed[_2_] Excel Discussion (Misc queries) 1 July 17th 07 06:40 AM
Change the width of a single column in a column chart Dave Charts and Charting in Excel 2 December 13th 04 07:25 PM


All times are GMT +1. The time now is 06:05 AM.

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

About Us

"It's about Microsoft Excel"