Results 1 to 5 of 5
  1. #1
    4 Star Lounger
    Join Date
    Aug 2001
    Location
    London, UK
    Posts
    516
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Auto fit contents of Excel using code (Office 2000)

    Is there anyway I could do
    Format-Column-Auto fit selection
    Automatically using VB code??

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Auto fit contents of Excel using code (Office 2000)

    Yes, you need something like:
    Worksheets("Sheet1").Columns("A:I").AutoFit
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    4 Star Lounger
    Join Date
    Aug 2001
    Location
    London, UK
    Posts
    516
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Auto fit contents of Excel using code (Office 2000)

    Hi Rory!
    Thanx for helping, I used the following bit of code
    Worksheets("Sheet1").Columns("A:S").AutoFit
    But it gve me the following error message:
    Subscribt out of range
    Why???

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Auto fit contents of Excel using code (Office 2000)

    Hi,
    Is your sheet actually called Sheet1? If not, either replace "Sheet1" with its actual name or use Worksheets(1) instead.
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    4 Star Lounger
    Join Date
    Aug 2001
    Location
    London, UK
    Posts
    516
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Auto fit contents of Excel using code (Office 2000)

    Thanx Rory!
    I've changed the name of the sheet and it works <img src=/S/joy.gif border=0 alt=joy width=23 height=23>
    <img src=/S/bow.gif border=0 alt=bow width=15 height=15>

Posting Permissions

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