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.
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.
Learn more about Allen...
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.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (1943) applies to Microsoft Excel 97, 2000, 2002, and 2003.
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!