View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Larry A[_3_] Larry A[_3_] is offline
external usenet poster
 
Posts: 15
Default Why does macro speed slow after Excel Print or Print Preview?

The below macro, which I have left literally as coded, runs very quickly
from Excel -- until, in Excel, I do either a print or print preview in
native Excel, not VBA. After which, the macro, when next invoked, runs
about 10 times slower which makes it performance unacceptable. If I close
and reopen the spreadsheet, however, it seems to reset the internal
environment and the macro once again runs nicely. Until the next print or
print preview.

The macro is intended to display only selected portions of a large table
spanning about 12000 rows. The print range, however, is set to run from the
top of the table to just one past the end of the table, or row 12001, in
order to include all lines currently unhidden. Excel takes a little time
working through this formatting before displaying. And I wonder if this is
leaving Excel slightly corrupted. I don't see how the issue could be the
macro, but I have included below for reference.

Version is Excel 2002. Any thoughts? Thanks in advance. Larry.

Private Sub cmdPlusOne_Click()
Dim i, curr_level, row As Integer, c As String
Worksheets("FOCUS").Activate
c = ActiveCell.Address
row = ActiveCell.row
With Range("A" & row)
curr_level = .Offset(0, 0)
For i = 1 To 20000
If (.Offset(i, 0) = Null) Or (.Offset(i, 0) <= curr_level) Then
Exit For
ElseIf .Offset(i, 0) = curr_level + 1 Then
Rows("" & (row + i) & ":" & (row + i) & "").Select
Selection.EntireRow.Hidden = False
End If
Next i
Range(c).Select
End With
End Sub


(Just as further FYI, the table being processed by the macro above is
actually an outline. Level refers to the outline indent level of the current
active cell. The macro is intended to then unhide any entries one level
further down in the outline.)