Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Setting the Width of a column

I need to set the width of a column. I am using the following code

ActiveSheet.Columns("A:A").Width = 57

This should set the width of the column to approximately 0.8 inches (57/72).

I am getting the following error message:

Run-Time error '1004'

Unable to set the width property of the Range class.

Why not?

Nirmal
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Setting the Width of a column

Nirmal,

Because the property .Width is read only. The property .ColumnWidth can be
modified.

HTH,
Bernie
MS Excel MVP


"Nirmal Singh" wrote in
message ...
I need to set the width of a column. I am using the following code

ActiveSheet.Columns("A:A").Width = 57

This should set the width of the column to approximately 0.8 inches

(57/72).

I am getting the following error message:

Run-Time error '1004'

Unable to set the width property of the Range class.

Why not?

Nirmal



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Setting the Width of a column

Hi Nirmal,

Try:

ActiveSheet.Columns("A:A").ColumnWidth = 57

---
Regards,
Norman



"Nirmal Singh" wrote in
message ...
I need to set the width of a column. I am using the following code

ActiveSheet.Columns("A:A").Width = 57

This should set the width of the column to approximately 0.8 inches
(57/72).

I am getting the following error message:

Run-Time error '1004'

Unable to set the width property of the Range class.

Why not?

Nirmal



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Setting the Width of a column

On Fri, 27 May 2005 11:25:19 -0400, "Bernie Deitrick" <deitbe @ consumer dot org wrote:


Because the property .Width is read only. The property .ColumnWidth can be
modified.


Thanks for that Bernie. I still need to set my columns to specific sizes to ensure that all my data
gets printed properly.

The ColumnWidth property is set in terms of the number of characters that will fit in a column. How
can I use this to set the absolute width of a column?

Nirmal

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Setting the Width of a column

Nirmal,

You can get close (but never get exact due to limitations on the accuracy of
the character size) using something like:

Sub Macro1()
Dim NewWidth As Double

NewWidth = 17

With Range("A1").EntireColumn
MsgBox "Column A was this wide: " & .Width
.ColumnWidth = NewWidth * .ColumnWidth / .Width
.ColumnWidth = NewWidth * .ColumnWidth / .Width
MsgBox "Column A is this now wide: " & .Width
End With

End Sub

Note that the .ColumnWidth is set twice: the iteration is necessary for some
reason....

HTH,
Bernie
MS Excel MVP


"Nirmal Singh" wrote in
message ...
On Fri, 27 May 2005 11:25:19 -0400, "Bernie Deitrick" <deitbe @ consumer

dot org wrote:


Because the property .Width is read only. The property .ColumnWidth can

be
modified.


Thanks for that Bernie. I still need to set my columns to specific sizes

to ensure that all my data
gets printed properly.

The ColumnWidth property is set in terms of the number of characters that

will fit in a column. How
can I use this to set the absolute width of a column?

Nirmal





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Setting the Width of a column

On Fri, 27 May 2005 11:47:44 -0400, "Bernie Deitrick" <deitbe @ consumer dot org wrote:

You can get close (but never get exact due to limitations on the accuracy of
the character size) using something like:

Sub Macro1()
Dim NewWidth As Double

NewWidth = 17

With Range("A1").EntireColumn
MsgBox "Column A was this wide: " & .Width
.ColumnWidth = NewWidth * .ColumnWidth / .Width
.ColumnWidth = NewWidth * .ColumnWidth / .Width
MsgBox "Column A is this now wide: " & .Width
End With

End Sub

Thanks Bernie, that's close enough for me.

Nirmal
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
setting column width James Excel Discussion (Misc queries) 1 July 11th 08 12:02 AM
Setting column width in a table Box815 Excel Discussion (Misc queries) 4 October 11th 06 06:34 AM
Setting column width for blank columns gmr7 Excel Discussion (Misc queries) 0 January 17th 06 03:16 PM
Setting Column Width on Imported Data B.C.Lioness Excel Discussion (Misc queries) 0 May 16th 05 09:41 PM
Setting column width Brad E.[_2_] Excel Programming 2 January 21st 05 05:26 PM


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

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"