Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. 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

Written by Allen Wyatt (last updated November 30, 2024)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021


1

It is not unusual to use macros to process data and format output in a 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

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9333) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. 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

Deleting a Page

Want to delete the current page? There is no automatic command to perform this task in Word, but you can create your own ...

Discover More

Creating Multiple Blank Documents in One Step

Word makes it easy to create a new, blank document. What if you want to create more than one document at a time, however? ...

Discover More

Changing the Start Screen's Theme

You'll spend a lot of time viewing the Start screen in Windows. If you want to change up things, you can modify which ...

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)

Counting Empty Colored Cells

There are a variety of ways that you might want to count the cells in your worksheet. One way is to figure out how many ...

Discover More

Renaming a Macro

Got a macro that doesn't have quite the right name? You can rename the macro by following these simple steps.

Discover More

Counting All Characters

Need to know how many characters there are in a workbook? You can find out easily with the handy macro introduced in this ...

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}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. 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 2 + 2?

2024-11-30 12:31:43

J. Woolley

The Tip refers to the ColumnWidth property as "the width of the column in characters, based on the current font settings." It is actually based on the width of the character 0 (zero) in the Normal style.
My Excel Toolbox includes the following macros related to this subject:
SetColumnWidthPixels - Set the width in pixels for all columns in Selection
SetColumnWidthByCell - Make the width of ActiveCell's column fit its contents
AdjustColumnWidths - Adjust the width of selected columns by a fixed increment or a proportional multiplier
See https://sites.google.com/view/MyExcelToolbox/
For more on this subject see https://excelribbon.tips.net/T006242 and https://excelribbon.tips.net/T011302


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.