Ans : ➯ The AutoFit feature automatically resizes columns or rows to fit the cell in each column or row that has the widest or tallest contents.
➯ We can use below steps to AutoFit Column Or Rows.
1) Double Click on Column Headers Right Border(or the row header's bottom border). It will automatically resize.
2) Goto Home Tab ➯ Format ➯ Click On AutoFit Row/Column
⚝ AutoFit Columns using VBA
Sub AutoFit()
Range("A1").EntireColumn.AutoFit
'OR
Sheet1.UsedRange.EntireColumn.AutoFit
'OR
Columns("A:B").EntireColumn.AutoFit
'OR
Range("A:B").EntireColumn.AutoFit
'OR
Sheet2.Cells.EntireColumn.AutoFit
End Sub
'Autofit All Used Columns
Sub AutofitAllUsed()
Dim x As Integer
Dim Wks As Worksheet
Set Wks = Thisworkbook.sheets(Sheet1.Name)
For x = 1 To Wks.UsedRange.Columns.Count
Columns(x).EntireColumn.AutoFit
Next
End Sub
Tags:
AutoFit Columns