View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
joeu2004[_2_] joeu2004[_2_] is offline
external usenet poster
 
Posts: 829
Default this code is VERY slow, is it the code or perhaps a worksheet issue

"Howard" wrote:
Excel 2010
When I run this code it takes a tiny bit less than
one second for each entry with no "X" in the column
to the left and at least a full second if it has to
cut & paste the resized cells in response to the "X"
in the column to the left.
The worksheet also seems to be slower than normal using
common sheet procedures like selecting a couple of cells
and draging them to another column, same slowness with
cut and paste of 150 to 250 entries in a column to another
column.
The sheets data is about 50 columns by 300 rows and a
"storage column" just over 1000 rows.


From your description, the problem is not where the size of the "used range"
in the worksheet. Instead, I suspect it is due to a large number of
"volatile" formulas (or dependencies on them) and/or the use of full-column
ranges like A:A.

Those issues should be addressed. But there are a number of things that you
can do to improve the run-time of the macro, despite those issues.

At a minimum, you should disable ScreenUpdating and set Manual calculation
mode. If you have any event macros, you might want to disable events as
well.

Try this (note also the change in Dim j):

Option Explicit
Sub CopyLeft()
'activecell must start row 1 to row 16 of column
Dim c As Range
Dim j As Long ' *** unrelated improvement ***
Dim st as Double ' *** debug ***
st = Timer ' *** debug ***
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
.EnableEvents = False
End With
ActiveCell.End(xlDown).Select
j = ActiveCell.End(xlDown).Row
ActiveCell.Resize(j - 16, 1).Select
With Selection
For Each c In Selection
If c.Offset(0, -1).Value = "X" Then
c.Resize(1, 2).Cut c.Offset(0, -2)
End If
Next
End With
' *** execute these statements in Immed Window ***
' *** if macro should abort for any reason ***
With Application
.EnableEvents = True
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
' *** Timer-st is not valid across midnight ***
MsgBox Format(Timer - st, "0.000") & " sec" ' *** debug ***
End Sub