Columns Autofit in Excel 'VBA'

 Columns Autofit in Excel

In Microsoft Excel, autofitting columns allows you to automatically adjust the width of a column to fit the contents within it. Here's how you can autofit columns:


Method 1: Autofit Column Width Using the Ribbon:

Select the Column(s):

Click on the column letter(s) at the top of the Excel sheet to select the column(s) you want to autofit.

Autofit from the Ribbon:

Go to the "Home" tab on the ribbon.

In the "Cells" group, you will find an option called "Format."

Hover over the "Format" option, and a menu will appear.

Click on "AutoFit Column Width."


Method 2: Autofit Column Width Using the Mouse:

Hover Between Column Headers:

Position your mouse pointer on the line between two column headers.

Double-Click:

Double-click the line between the column headers. Excel will automatically adjust the column width to fit the content in that column.


Method 3: Autofit Column Width Using the Context Menu:

Select the Column(s):

Right-click on the column letter(s) at the top of the Excel sheet to select the column(s).

Access the Context Menu:

Right-click on the selected column(s).

Choose "AutoFit Column Width":

From the context menu that appears, select "AutoFit Column Width."


Method 4: Using the Keyboard Shortcuts:

Select the Column(s):

Press and hold the "Shift" key and use the arrow keys to select the column(s).

Autofit Column Width:

Press Alt + H to go to the Home tab, then press O for Format, and finally press I for Column Width. This will autofit the selected column(s).

Method 5: Using the VBA:


Right Click on Sheet Name > Manu will appear and click on 'VIEW CODE' 

Sheet VBA Code window will open. 

In Workspace, Change 'General' to 'Worksheet'

Enter the Follow Code: 

cells.EntireColumn.AutoFit

Close the Code sheet and Check Magic.

It applies on how sheet.


Comments

Popular posts from this blog

مائیکروسافٹ ایکسل کا تعارف

نظرة عامة على العرض التقديمي المرئي لبرنامج MS Excel

MS Excel Visual Presentation Overview