Autofit Rows using Macros (VBA) in Excel:
In this article, we are going to see the steps to Autofit Rows using Macros in Excel Office 365 with an example. Let’s get into this article!! Get an official version of MS Excel from the following link: https://www.microsoft.com/en-in/microsoft-365/excel
Steps to Autofit Rows using Macros:
To autofit rows in an Excel spreadsheet using Macros, follow the below steps.
- In the below example, you can see the rows that are not in the proper order. So we are going to autofit rows using the VBA & Macros.
- Go to the Developer Tab, choose the Visual Basic option in the Code section.
- You need to activate the sheet where you want to autofit the rows.
- Now, enter the below code.
VBA code for autofit rows
Sub AutoFitAllRows()
Cells.Select
‘Now, you can see the result!!
Cells.EntireRow.AutoFit
End Sub
- You need to save the code by selecting it. Then close the window.
- Then, open the sheet that contains the data, and on the Developer Tab, ** choose the Macros option in the Code** section.
- You have to make sure that your Macro is selected and click the Run button.
- Now, all the rows are automatically fitted in the Excel spreadsheet.
Verdict:
In this article, you can clearly understand the steps to Autofit Rows using Macros in Excel Office 365 with an example. Leave your suggestions in the below comment section. Thanks for visiting Geek Excel. Keep Learning!!
Top comments (0)