Set Range ColumnWidth and RowHeight in Pixels RRS feed

  • Question

  • I need to draw a gird for visual demonstration purposes.  I want to set the ColumnWidth and RowHeight of a Range using pixels (not "character units" and points).  It's my understanding ColumnWidth and RowHeight are "character units" based on the selected font and Width and Height are read only points.  

    Here is some pseudo code of what I'm trying to accomplish. Below is an image of column width and row height at 20 pixels I set manually.  I need to do this via code.

    Sub SetRangeGrid(rng As Range, w As Long, h As Long)
    'w: column width in pixels
    'h: row height in pixels
        rng.ColumnWidth = GetColumnWidth(w)
        rng.RowHeight = GetRowHeight(h)
    End Sub
    Function GetColumnWidth(pixels As Long) As Double
    ' convert pixels to column width (in characters)
    End Function
    Function GetRowHeight(pixels As Long) As Double
    ' convert pixels to row height (in characters)
    End Function


    • Edited by Ryan0827 Tuesday, September 24, 2019 9:04 PM
    Tuesday, September 24, 2019 9:03 PM

All replies