Many thanks for quite a spectrum of suggestions!
erAck’s mention of WIDTH does indeed reflect my using this CELL function, resulting in a number of unknown units. Why, oh why can this not be refined by the excellent LO programmers to a cell’s property WIDTH in cm/mm? This is currently NOT the case: this function on a cell of 2.25 cm width brings a result=11! What a waste of a potentially useful function. Imagine a further development whereby n columns of equal width have to fit a page!
May I point out that, on my test page, I have a table that fits the page. Below this, I have written in a row of ‘dead’ cells the width of each particular column, the SUM at the end, of course.
LeroyG’s visually adjustment of the column-widths would demand a time-consuming procedure, resulting in finely varied widths.
You are correct, eeigor, in assuming I do not want to scale the sheets, just tables OF VARYING columns to FILL the sheets.
Why, oh why did Excel introduce it that way.
@ALOmgb41238, what’s stopping you from manually adjusting the width of the columns so that the total width of the ranges is the same on different sheets? Wrap text automatically is on.
BTW: Summing column widths and looking for SheetCellRange.Size.Width
won’t necessarily yield the same result. Column width isn’t changed when a column gets hidden. In the same way hidden and filtered rows keep their .Height
value.
“ask” some cell near the “border” for its …Position.X and …Position.Y -property
Well, it’s just Basic - and it even uses VBAsupport.
However, it should work.
Option Explicit
Option VBAsupport 1
Function cellRangeMeasurement(pRangeRef As Object, _
pOrient As String, _
Optional pIncludeHidden As Boolean)
cellRangeMeasurement = ":err:"
Dim rg As Object, width As Double, height As Double, _
uC As Long, uR As Long, c As Long, r As Long
If IsMissing(pIncludeHidden) Then pIncludeHidden = False
On Local Error Goto fail
rg = pRangeRef.cellRange
If pIncludeHidden Then
width = 0
height = 0
uC = rg.Columns.Count - 1
uR = rg.Rows.Count - 1
For c = 0 To uC
width = width + rg.Columns(c).Width
Next c
For r = 0 To uR
height = height + rg.Rows(r).Height
Next r
Else
width = rg.Size.Width
height = rg.Size.Height
EndIf
REM Unit now is cm.
Select Case Ucase(Left(pOrient, 1))
Case "W"
cellRangeMeasurement = width/1000
Case "H"
cellRangeMeasurement = height/1000
Case "B"
cellRangeMeasurement = "" & (width*0.001) & _
"+" & (height*0.001) & "i"
End Select
fail:
End Function
Example document containing the code:
disask71715cellRangeAreas.ods (19.0 KB)
This is one of the “spreadsheet traditionals” which exists for backwards compatibility with other programs. It has to be compatible or dropped.
Here’s one where the column can automatically structure the desired character width and all that’s necessary is to select the appropriate columns and set them to “Optimal Width” - try it on the sample.
Carefully placing and hiding rows or indeed just concealing the text by colouring it white removes the dross from the bottom of the pages.
Even if the “fake space string” is shorter than the actual maximum cell contents it will make no difference to “Optimal”.
It won’t be millimetre precise with proportional fonts but I suspect an easy “close enough” result would suffice
Column Widths2.ods (16.2 KB)
Well, @WhiteKnight, I am neither a damsel nor am I, methinks, no longer in distress. For, your Column Widths2.ods seems to have cracked it. I need to have some less-tired grey matter! Meanwhile, Christmas and Joseph et al --with Monty Python coconuts, stage left-- are closing in: Thyme to peruse your ideas.
Many thanks to all who have made this query full of promising uses.
Now that it’s refreshed… hopefully, you realise that all the steps - separated for clarity - can be consolidated into the relevant cells with the resulting zeros.
Enjoy Xmas
Perhaps you could mark it as the solution so later readers don’t need to wade through all the intriguing technical challenges to find it