VBA: Autofit All Columns Used

September 8th, 2004 | Categories: VBA | Tags:
-->

A popular Yahoo Search the past week has been to Autofit All Columns used in a worksheet from VBA. Combining the VBA to Autofit A Range, Count the Number of Used Columns, and a loop will do just that.

The following code autofits from VBA all used columns:

Sub AutofitAllUsed()

Dim x As Integer

For x = 1 To ActiveSheet.UsedRange.Columns.Count
     Columns(x).EntireColumn.autofit
Next x

End Sub
Can't get the tutorial to work for you? Need help with your code?
Get answers right away at our AE Excel Support Forums!
  1. October 8th, 2009 at 10:40
    Reply | Quote | #1

    It works! After much searching, I’m very pleased and very grateful!

  2. Adijo
    February 8th, 2011 at 10:52
    Reply | Quote | #2

    Wow ! Thanks !