Making Squares

Written by Allen Wyatt (last updated August 20, 2022)
This tip applies to Excel 97, 2000, 2002, and 2003


One of the (many) frustrating things about Excel is that it uses different units of measurement to specify the height of rows and the width of columns.

Row height is pretty straightforward—it is measured in points. Column width, however, is measured in character widths. If your Standard style is set to Courier 10, then a column width of 12 means that you can fit exactly twelve characters in a given column. For proportional fonts, the character 0 is used to count the characters. (Yup, it's absurd.)

This leads to problems if you want the height and width of a particular cell to match, thereby making a square. Fortunately, with a little macro wizardry you can bypass this oddity of Excel and achieve the desired results. Consider the MakeSquare macro:

Sub MakeSquare()
    Dim WPChar As Double
    Dim DInch As Double
    Dim Temp As String
    
    Temp = InputBox("Height and width in inches?")
    DInch = Val(Temp)
    If DInch > 0 And DInch < 2.5 Then
        For Each c In ActiveWindow.RangeSelection.Columns
            WPChar = c.Width / c.ColumnWidth
            c.ColumnWidth = ((DInch * 72) / WPChar)
        Next c
        For Each r In ActiveWindow.RangeSelection.Rows
            r.RowHeight = (DInch * 72)
        Next r
    End If
End Sub

This macro prompts you for the dimension of the square you want to create, and then calculates exactly how wide and high to set each cell. You can run the macro with a single cell selected, or you can make a larger selection set.

The "math magic" is done in the calculating of the WPChar variable. This is set to a value derived by dividing the width of the column in points (returned by the Width property) by the width of the column in characters (returned by the ColumnWidth property). This value, which is the number of points in a character at the current settings, is then used to calculate how many characters should be used to set the width in the next program line.

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 (1943) applies to Microsoft Excel 97, 2000, 2002, and 2003.

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

Transferring Fonts

Do you want to transfer fonts from one computer system to another? It is relatively easy to do, but there is one ...

Discover More

Searching for Breaks

Word allows you to insert different types of breaks in your text that help control how your document is paginated. If you ...

Discover More

Diagonal Borders in a Conditional Format

Conditional formatting is a great tool for changing how your data looks based on the data itself. Excel won't allow you ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (menu)

Setting Horizontal Alignment

You can horizontally align the information in a cell in any of eight different ways. This tip explains not only how to do ...

Discover More

Setting Vertical Alignment

Excel allows you to adjust not only the horizontal alignment of values in a cell, but also the vertical alignment. This ...

Discover More

Number Formatting Shortcuts

Keyboard shortcuts can save time and make developing a workbook much easier. Here's how to apply the most common of ...

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 four minus 0?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon 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.