VBA: Autofit Columns
After you manipulate a worksheet with VBA it may be necessary to Autofit your columns to present the nicest end result possible. Here’s how to autofit columns using VBA.
This code autofits columns A and B. The autofit is applied to the active sheet.
Columns("A:B").EntireColumn.Autofit
Can't get the tutorial to work for you? Need help with your code?
Get answers right away at our AE Excel Support Forums!
Get answers right away at our AE Excel Support Forums!



This works for me Perfectly. Thanks a million.
A Excel VBA macro in Excel 2007 and 2003 that performs several processes calls another macro that auto fits certain rows, however, the auto fit portion does not produce the intended purpose. However, if I use the Step Into function to execute the macro, the auto fit portion executes properly.
Do you have any ideaas that might solve this problem?
A Excel VBA macro in Excel 2007 and 2003 that performs several processes calls another macro that auto fits certain rows height, however, the auto fit portion does not produce the intended purpose. However, if I use the Step Into function to execute the macro, the auto fit portion executes properly.
Do you have any ideaas that might solve this problem?
Perhaps you need to select the sheet first in the code. I’m guessing when you are stepping through the code you are viewing the sheet you are performing the operation on, but when running the macro this sheet is not automatically selected.
Try putting this bit of code before your autofit code:
Sheets(sheetname).select
Andy
)