Adjust Column Width

Question: How do I adjust the column width to fit the cell contents?

Answer: There are many ways to do this.  One way is to simply position your cursor betwen two columns in the header.  You’ll see the cursor change similar to that in the screenshot below.

At this point, you have two options.  One, you can click and drag to the right to increase the width of the left column.  Or two, you can double click and Excel will automatically adjust the column width to fit the contents of the cells.

So what if you have more than one column width to adjust?  What if you wanted all column widths to adjust?  Simple!  Just select all cells (press CTRL+A), or click on the upper left corner of the grid as shown below.

After selecting all cells, now you go to the Home tab, look for the Cells section and click on Format, and select the Autofit Column Width option. 

Now, suppose you wanted to do it through code using VBA?  Easy! Here’s an example of how you would do it:

Sub AutoFitColumnWidth()
   
    'if you wanted to autofit column A, use this:
    ActiveSheet.Range("A1").EntireColumn.AutoFit
   
    'if you wanted to autofit all columns, then use this:
    ActiveSheet.Columns.AutoFit
End Sub
This entry was posted in How To, VBA and tagged , . Bookmark the permalink.



Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>