VBA code Auto Fit Columns & Rows


  •  
    Auto Fit Columns

Sub AutoFitColumns()

    'Replace A1:C10 with the range of columns you want to auto-fit

    Range("A1:C10").Columns.AutoFit

End Sub


This code will auto-fit the columns in the range specified in the code. Replace "A1:C10" with the range of columns you want to auto-fit. The .Columns.AutoFit method will adjust the width of each column in the range to fit the widest cell contents.


  • Auto Fit Rows
Sub AutoFitRows()

    'Replace A1:A10 with the range of rows you want to auto-fit

    Range("A1:A10").Rows.AutoFit

End Sub



This code will auto-fit the rows in the range specified in the code. Replace "A1:A10" with the range of rows you want to auto-fit. The .Rows.AutoFit method will adjust the height of each row in the range to fit the tallest cell contents.

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.