Results 1 to 5 of 5

Problem with Autofit loop for each worksheet

Threaded View

Airgaf Problem with Autofit loop for... 02-23-2011, 08:23 PM
rylo Re: Problem with Autofit loop... 02-23-2011, 09:01 PM
broro183 Re: Problem with Autofit loop... 02-23-2011, 10:37 PM
Airgaf Re: Problem with Autofit loop... 02-24-2011, 01:33 PM
broro183 Re: Problem with Autofit loop... 02-24-2011, 05:08 PM
  1. #1
    Registered User
    Join Date
    02-23-2011
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    31

    Problem with Autofit loop for each worksheet

    Hi everyone,

    First day here and I've run into two problems. I was fortunate enough to have my first one quickly answered by Charles. I'm pretty sure this forum will go 2 for 2 today since this problem seems to be a lot simpler (at least amount of code wise).

    This macro is going to be used by multiple workbooks (but only one at a time). Each workbook will have a different number of worksheets, but will always need Columns A through H to be autofitted. Here is my code:

    Sub FitNow()
    'Autofit main columns of workbook
    Dim i, j As Integer
    Set j = Sheet.Count

    For i = 1 To j
    ActiveWorkbook.Sheets(i).Columns("A:H").EntireColumn.AutoFit
    Next

    End Sub
    Any idea why this isn't working? I'm pretty bad at loops, so that could be the main reason.

    Thank you in advance for your help and insight
    Last edited by Airgaf; 02-24-2011 at 01:38 PM.

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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