+ Reply to Thread
Results 1 to 4 of 4

Auto setting column widths accross a whole workbook

  1. #1
    vMaster
    Guest

    Auto setting column widths accross a whole workbook


    I was trying to write a macro to select all columns on all sheets in
    the workbook and force the columns to fit to the data. However, even
    using a tip here to select all the sheets, I could only get it to apply
    automatic widths to the current sheet.

    Is it possible to write a macro to do this?

    Any help apreciated. Excel 2003.


  2. #2
    Xcelion
    Guest

    RE: Auto setting column widths accross a whole workbook

    Hi Vmaster
    Try ou this

    Sub AutoFitColumns()
    Dim ws As Worksheet
    For Each ws In ThisWorkbook.Worksheets
    ws.Columns.AutoFit
    Next
    End Sub




    "vMaster" wrote:

    >
    > I was trying to write a macro to select all columns on all sheets in
    > the workbook and force the columns to fit to the data. However, even
    > using a tip here to select all the sheets, I could only get it to apply
    > automatic widths to the current sheet.
    >
    > Is it possible to write a macro to do this?
    >
    > Any help apreciated. Excel 2003.
    >
    >


  3. #3
    vMaster
    Guest

    Re: Auto setting column widths accross a whole workbook

    For some reason this did nothing! Is 'ThisWorkbook' proper syntax?

    Anyway this did work, not really sure what the difference with! I got
    there with your help. Thanks!

    Sub Autowidth()
    '
    ' Autowidth Macro
    ' Macro recorded 26/12/2005 by
    '
    '
    Dim ws As Worksheet
    For Each ws In ActiveWorkbook.Worksheets
    ws.Columns.AutoFit
    Next
    End Sub


  4. #4
    Xcelion
    Guest

    Re: Auto setting column widths accross a whole workbook

    HI Vmaster,
    Thisworkbook refers to the workbook on which you have written the
    function,and active workbook refers to the workbook which is active now

    Thanks
    Xcelion



    "vMaster" wrote:

    > For some reason this did nothing! Is 'ThisWorkbook' proper syntax?
    >
    > Anyway this did work, not really sure what the difference with! I got
    > there with your help. Thanks!
    >
    > Sub Autowidth()
    > '
    > ' Autowidth Macro
    > ' Macro recorded 26/12/2005 by
    > '
    > '
    > Dim ws As Worksheet
    > For Each ws In ActiveWorkbook.Worksheets
    > ws.Columns.AutoFit
    > Next
    > End Sub
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1