ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   AutoFit Columns in a new Worksheet (https://www.excelbanter.com/excel-programming/380678-re-autofit-columns-new-worksheet.html)

Jon Peltier

AutoFit Columns in a new Worksheet
 
Try something like

GridSheet.UsedRange.EntireColumn.AutoFit

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"Andy_WS" wrote in message
...
We had Office 2003 installed and we ran a VBscript that would auto create
workbooks depending on the data retrieved. At the bottom of the script we
used this statement:

GridSheet.Columns("A:ZZ").AutoFit ' Prettyprint


We recently upgraded to Office 2007 and the script returned a mismatch
error
when trying to AutoFit the columns. We modified the statment to this:

GridSheet.Columns("A:IV").AutoFit ' Prettyprint

If the Columns range is changed to ("A:IW") it will return a "Type
mismatch
error" again. There seems to be a limit now?

Does anyone know what has changed from 2003 to 2007 that would cause this
to
happen or does anyone know of a better way to use this statement?

Basically we want the script to AutoFit all columns contained in the
worksheet.

Thank You for your help in advance

Andy





Andy_WS

AutoFit Columns in a new Worksheet
 
Jon,

Thank you. That worked perfectly.

Andy

"Jon Peltier" wrote:

Try something like

GridSheet.UsedRange.EntireColumn.AutoFit

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"Andy_WS" wrote in message
...
We had Office 2003 installed and we ran a VBscript that would auto create
workbooks depending on the data retrieved. At the bottom of the script we
used this statement:

GridSheet.Columns("A:ZZ").AutoFit ' Prettyprint


We recently upgraded to Office 2007 and the script returned a mismatch
error
when trying to AutoFit the columns. We modified the statment to this:

GridSheet.Columns("A:IV").AutoFit ' Prettyprint

If the Columns range is changed to ("A:IW") it will return a "Type
mismatch
error" again. There seems to be a limit now?

Does anyone know what has changed from 2003 to 2007 that would cause this
to
happen or does anyone know of a better way to use this statement?

Basically we want the script to AutoFit all columns contained in the
worksheet.

Thank You for your help in advance

Andy







All times are GMT +1. The time now is 10:04 PM.

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