Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simply setting the column width in Excel with VBA

Status
Not open for further replies.

BluByU

IS-IT--Management
Jul 29, 2003
35
0
0
US
I've done a forum search, but none of the topics seems to have a solution that works. I simply need to set the ".columnwidth" property of a spreadsheet to a certain width. I tried "autofit" (which is preferable to me)that also didn't seem to work. Here is what I am doing in VBA:

ThisWorkbook.Worksheets(2).Columns("A1:CZ500").EntireColumn.ColumnWidth = ??

Where "??" is the column width. None of the things I've tried seems to have any effect. Thanks in advance for your help.
 
Worksheets("Sheet1").Columns("A:I").AutoFit


[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
And what about this ?
ThisWorkbook.Worksheets(2).Columns("A:CZ").AutoFit

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
or if you know what size you want it

Worksheets("Sheet1").Columns("A").ColumnWidth = 10

<- can't believe how quick PHV is on the draw

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Thanks a lot! That fixed it. I guess the "row" numbers must have been confusing Excel. This is a great forum!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top