Widening Multiple Columns Proportionally

by Allen Wyatt
(last updated February 6, 2016)

5

Keith has a worksheet that uses columns A through H. He would like to be able to widen each column by a proportional amount. For instance, if he selects all 8 columns, it would be great if he could grab the right edge of column H and as he drags right, all of the columns would be proportionally spaced out. He wonders if there is a way to do this type of column widening.

To better understand what Keith is talking about, perhaps an example is in order. The normal way of adjusting column width using the mouse is to select the columns and then drag a divider between the column headers to the right or left. Let's say that column A's width is 5, column B is 10, and column C is 15. If you select A:C and drag the divider at the right side of the column C header to 20, that is an increase of 33% for column C. Ideally, both column A and B would also be resized by 33% (as Keith desires), but they are, instead, both set to a width of 20 to match column C.

Further, holding down a modifier key (Ctrl, Alt, or Shift) as you drag the mouse has no effect; the column widths are still all set equal to each other. If you try to right-click and drag, that does nothing except display a Context menu. Thus, from all the testing we've been able to do, there is no way to proportionally adjust column widths in in Excel that we've been able to discover.

Perhaps the easiest way is to use a macro to adjust the column widths. The following is a good example of such an approach.

Sub ProportionalWidth()
    Dim C As Range
    Dim sRaw As String
    Dim sTemp As String
    Dim P As Single

    sRaw = InputBox("Increase width by how what % (0 to 100)?")
    P = Val(sRaw)
    If P >= 0 And P <= 100 Then
        P = 1 + (P / 100)
        sTemp = ""
        For Each C In Selection.Columns
            sTemp = sTemp & "Column " & ColumnLetter(C.Column)
            sTemp = sTemp & ": " & C.ColumnWidth & " ==> "
            C.ColumnWidth = C.ColumnWidth * P
            sTemp = sTemp & C.ColumnWidth & vbCrLf
        Next C
        MsgBox sTemp
    Else
        MsgBox "Out of range; no adjustment made"
    End If
End Sub
Function ColumnLetter(Col As Long) As String
    Dim Arr
    Arr = Split(Cells(1, Col).Address(True, False), "$")
    ColumnLetter = Arr(0)
End Function

There are actually two macros in this example. The first (ProportionalWidth) changes the width of whatever columns you've selected. The second (ColumnLetter) is used to convert a numeric column number into the column letters. It is only used in putting together the report (in sTemp) of the before and after widths of the columns.

When you select columns and run the macro, it prompts you for how much wider you want to make those columns. Enter a number between 0 and 100, click OK, and the columns are widened by that percentage. In addition, you'll see a message box that shows the original width of each column and the adjusted width.

Note that this macro only widens columns. If you wanted use it to also make columns proportionally narrower, you would need to modify it to, perhaps, handle negative values.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13429) applies to Microsoft Excel 2007, 2010, 2013, and 2016.

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

Peculiar Font Differences

Have you noticed page layout differences when you open a document on different systems? There are a number of reasons why ...

Discover More

Saving Changes when Closing

If you write a macro that makes changes to a document, you may want that macro to save those changes. There are several ways ...

Discover More

Turning Off Figure Caption Numbering

Ever want to use Word's automatic figure captioning feature, without the numbering? While there isn't a way to make this work ...

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)

Hiding Columns Not within a Date Range

Want to automatically hide some columns that don't meet a date criteria that you set? You can't do it automatically, but you ...

Discover More

Unhiding a Single Column

In a worksheet with lots of hidden columns it is a real pain to try to unhide just one or two columns. The best solution is ...

Discover More

Double-Clicking to Widen Columns Won't Work

One way you can widen the columns in a worksheet to fit whatever is in the column is by double-clicking the right edge of the ...

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 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 nine more than 8?

2016-04-16 06:50:06

Sally

Using the column headers, if you select a range of columns and double click the header divider between any of the selected columns, they will adjust proportionately to the contents of each column. For this, no macro is necessary.


2016-02-06 13:00:33

Willy Vanhaelen

This single macro does perecentages > 100 as well as negative % to narrow colmums:

Sub ProportionalWidth()
Dim C As Range, Dim sTemp As String, Dim P As Single
On Error GoTo notOK
P = InputBox("Enter % to increase/decrease width")
P = 1 + (P / 100)
For Each C In Selection.Columns
sTemp = sTemp & "Column " & Split(Cells(1, C.Column).Address, "$")(1)
sTemp = sTemp & ": " & C.ColumnWidth & " ==> "
C.ColumnWidth = C.ColumnWidth * P
sTemp = sTemp & C.ColumnWidth & vbCrLf
Next C
MsgBox sTemp
Exit Sub
notOK:
MsgBox "Out of range; no adjustment made"
End Sub


2016-02-06 08:25:02

Michael (Micky) Avidan

@Sally Duncan,
The tip refers to "Widening Multiple Columns Proportionally(!!!) AND NOT
"Optimal width for the contents of cells".
*** This was the original request/question from a user named: Keith.
--------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2016)
ISRAEL


2016-02-06 06:08:21

Gerhard Schweizer

Why limit the maximum to 100? Formula should also work for percentages >100


2016-02-06 05:03:46

Sally Duncan

There is also a very simple way to optimise column widths.
Using the column headers and (if necessary) the CTRL key, select the columns you wish to adjust. Move the mouse pointer over the border between any two of these column headers and double click. Each selected column adjusts to the optimal width for the contents. In my experience, adjusting each by a given value in a macro is less often necessary.


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.