Cell Widths and Heights

Mark F

Well-known Member
Joined
Jun 7, 2002
Messages
513
Office Version
  1. 365
Platform
  1. Windows
I am trying to create a cell which is 3cm wide and 11cm high.

I need to know the millimetre or centimetre equivalent to a pixel and a "row height".

I am assuming it is somewhere in user setup but I can't find it!

Can anyone help?
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Hi BD,

This should help you out (one of Microsoft's own bits of code I seem to remember):
Code:
'Microsoft Excel uses the font assigned in the Normal style as the basis for column
'widths. There is no direct way to assign exact column widths in inches or centimeters
'without trial and error.
'
'Excel bases its measurement of column widths on the number of digits (specifically,
'the number of zeros) in the column, using the Normal style font. (There are some
'fonts that have digits of different widths, but this is unusual.)
'
'For example, using the default font, a column with a width of 10 refers to the column
'width needed to display 10 non-bold, non-italic, Arial 10-point zeros. On a Macintosh
'computer, this same column width consists of 10 non-bold, non-italic Geneva 10-point
'zeros. Excel uses digits to determine column widths so that when you change the font
'for a style on a worksheet, the columns grow or shrink to display the specified
'number of digits in the column.
'
'Note that this method of determining column widths is not exact when you use other
'characters, such as spaces, dollar-signs, parentheses, and so on.
'
'This article provides sample Microsoft Visual Basic for Applications macros that
'allow you to set the row height and column width in either inches or centimeters.
'

Sub RowHeightInCentimeters()
    Dim cm As Single
    ' Get the row height in centimeters.
    cm = Application.InputBox("Enter Row Height in Centimeters", _
        "Row Height (cm)", Type:=1)
    ' If cancel button not pressed and a value entered.
    If cm Then
        ' Convert and set the row height
        Selection.RowHeight = Application.CentimetersToPoints(cm)
    End If
End Sub
                
Sub ColumnWidthInCentimeters()

    Dim cm As Single, points As Integer, savewidth As Integer
    Dim lowerwidth As Integer, upwidth As Integer, curwidth As Integer
    Dim Count As Integer

    ' Turn screen updating off.
    Application.ScreenUpdating = False
    ' Ask for the width in inches wanted.
    cm = Application.InputBox("Enter Column Width in Centimeters", _
        "Column Width (cm)", Type:=1)
    ' If cancel button for the input box was pressed, exit procedure.
    If cm = False Then Exit Sub
    ' Convert the cm entered to points.
    points = Application.CentimetersToPoints(cm)
    ' Save the current column width setting.
    savewidth = ActiveCell.ColumnWidth
    ' Set the column width to the maximum allowed.
    ActiveCell.ColumnWidth = 255
    ' If the points desired is greater than the points for 255
    ' characters...
    If points > ActiveCell.Width Then
        ' Display a message box because the size specified is too
        ' large and give the maximum allowed value.
        MsgBox "Width of " & cm & " is too large." & Chr(10) & _
            "The maximum value is " & _
            Format(ActiveCell.Width / 28.3464566929134, _
            "0.00"), vbOKOnly + vbExclamation, "Width Error"
        ' Reset the column width back to the original.
        ActiveCell.ColumnWidth = savewidth
        ' Exit the Sub.
        Exit Sub
    End If
    ' Set the lowerwidth and upper width variables.
    lowerwidth = 0
    upwidth = 255
    ' Set the column width to the middle of the allowed character
    ' range.
    ActiveCell.ColumnWidth = 127.5
    curwidth = ActiveCell.ColumnWidth
    ' Set the count to 0 so if it can't find an exact match it won't
    ' go on indefinitely.
    Count = 0
    ' Loop as long as the cell width in is different from width
    ' wanted and the count (iterations) of the loop is less than 20.
    While (ActiveCell.Width <> points) And (Count < 20)
        ' If active cell width is less than desired cell width.
        If ActiveCell.Width < points Then
            ' Reset lower width to current width.
            lowerwidth = curwidth
            ' set current column width to the midpoint of curwidth
            ' and upwidth.
            Selection.ColumnWidth = (curwidth + upwidth) / 2
        ' If active cell width is greater than desired cell width.
        Else
            ' Set upwidth to the curwidth.
            upwidth = curwidth
            ' Set column width to the mid point of curwidth and lower
            ' width.
            Selection.ColumnWidth = (curwidth + lowerwidth) / 2
        End If
        ' Set curwidth to the width of the column now.
        curwidth = ActiveCell.ColumnWidth
        ' Increment the count counter.
        Count = Count + 1
    Wend
End Sub
HTH
 
Upvote 0

Forum statistics

Threads
1,215,548
Messages
6,125,472
Members
449,231
Latest member
Sham Yousaf

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top