Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Setting Column Width in a Macro.

Setting Column Width in a Macro

by Allen Wyatt
(last updated November 7, 2016)

2

It is not unusual to use macros to process data and format output in an workbook. If you use macros to do this type of work, you may be interested in changing the width of a column using a macro. If so, you should pay attention to the ColumnWidth property. This property, when applied to a Column object, indicates the width of the column in characters, based on the current font settings.

For instance, the following code snippet steps through the columns in a selection and sets the width of each column to 10 characters:

For Each c In ActiveWindow.RangeSelection.Columns
    c.ColumnWidth = 10
Next c

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9333) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Setting Column Width in a Macro.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Controlling the Outline in the Document Map

When you display the Document Map, you are essentially looking at an outline of the document at the same time as you continue ...

Discover More

Changing Directories in a Macro

When a macro works with files, it often has to change between different directories on your disk drive. This is done using ...

Discover More

Easy Filtering Specifications for a PivotTable

When you want to include specific records from a source table into a PivotTable, you need to employ some sort of filtering. ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More ExcelTips (ribbon)

Converting Numbers Into Words

Write out a check and you need to include the digits for the amount of the check and the value of the check written out in ...

Discover More

Highlighting Pattern Violations

A common part of working with text strings in a worksheet is normalizing those strings so that they follow whatever rules ...

Discover More

Filling a Range of Cells with Values

When writing a macro, you may want to fill a range of cells with different values. The easiest way to do this is to use ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 8Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 6 - 3?

2014-01-28 05:46:49

Michael (Micky) Avidan

ColumnWidth is good but not excellent.
Normally, I prefer using: Selection.Columns.AutoFit
in such cases one does not need to know what values to declare for each column.
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2014)
ISRAEL


2014-01-27 10:49:30

Bryan

I think the loop is unnecessary. Selection.ColumnWidth = 10 does the same thing.


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.