View Single Post
  #22   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default RowHeight and AutoFit wit Merged Cells

Sorry about the double post.

"Peter T" <peter_t@discussions wrote in message

Of course go with whatever works best with your overall scenario. Just
looking at the snippet below I'd bet it would be a tad faster with
screenupdating disabled in an invisible instance. Other things you are

doing
might negate that.


Thought I'd better check and disabling screenupdating in an invisble
instance was just as I expected, a tad faster.

I poulated A1:A100 with some text then ran your code in a loop like this

With r1 ' .range("A1")
For r = 1 To 100
k = k + 1
If k = 5 Then k = 1
' k = Count Mod PerRow
'If symbols are used, no need to adjust rowheight
If Not bUseSymbols Then ' false
Select Case k

I don't understand why adjust you columnwidth's in each loop
..ColumnWidth = MergedAreaWidth
then
..ColumnWidth = SourceWidth
if indeed that's what you are doing, each time in a long loop

I adusted the widths in all 4 columns before start of loop then reset after
the loop. A significant speed gain. Also got another speed gain by merging
multiple areas in one go, vs your For j = 1 To k loop (I refered to the
method in an adjacent post).

Regards,
Peter T


k = count Mod PerRow
'If symbols are used, no need to adjust rowheight
If Not bUseSymbols Then
Select Case k
Case 1
Set rng = .Offset(r, 0)
Case 2
Set rng = Union(.Offset(r, 0), .Offset(r, 2))
Case 3
Set rng = Union(.Offset(r, 0), .Offset(r, 2),
.Offset(r, 4))
Case 4
Set rng = Union(.Offset(r, 0), .Offset(r, 2),
.Offset(r, 4), .Offset(r, 6))
End Select
SourceWidth = .Offset(r, 0).Columns(1).ColumnWidth
MergedAreaWidth = 2 * SourceWidth
With rng
.ColumnWidth = MergedAreaWidth
.WrapText = vbTrue
With .Rows(1)
.EntireRow.AutoFit
.RowHeight = .RowHeight
End With
.ColumnWidth = SourceWidth
End With
End If
For j = 1 To k
n = (j - 1) * 2 ' I yam merging 2 cells
.Application.Range(.Offset(r, n), .Offset(r, n +
1)).MergeCells = vbTrue
Next j