G
GS
Just for interest I set up 512 rows of data and reran my code revised
as follows, using the Timer as did Joeu2004.
It took 0.5313 secs in XL2003; 0.4844 secs in XL2007!
Layout is the same as my previous test. ("X" in colA for 256
non-contiguous rows, data in colsB:C for 512 contiguous rows)
Sub CopyLeft_v2()
Dim rng As Range, lRow As Long, dStart As Double
'Range to be checked is from row1 to resize constant above,
'where the active cell is in row1/column1 of the data to shift.
'//**assumes contiguous rows of data**
Set rng = ActiveCell.Resize(ActiveCell.End(xlDown).Row)
dStart = Timer
For lRow = 1 To rng.Rows.Count
With rng
With .Cells(lRow)
If .Offset(0, -1).Value = "X" Then _
.Resize(1, 2).Cut .Offset(0, -1)
End With '.Cells(lRow)
End With 'rng
Next 'lRow
Debug.Print Format(Timer - dStart, "0.0000") & " sec"
End Sub 'CopyLeft()
--
Garry
Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
as follows, using the Timer as did Joeu2004.
It took 0.5313 secs in XL2003; 0.4844 secs in XL2007!
Layout is the same as my previous test. ("X" in colA for 256
non-contiguous rows, data in colsB:C for 512 contiguous rows)
Sub CopyLeft_v2()
Dim rng As Range, lRow As Long, dStart As Double
'Range to be checked is from row1 to resize constant above,
'where the active cell is in row1/column1 of the data to shift.
'//**assumes contiguous rows of data**
Set rng = ActiveCell.Resize(ActiveCell.End(xlDown).Row)
dStart = Timer
For lRow = 1 To rng.Rows.Count
With rng
With .Cells(lRow)
If .Offset(0, -1).Value = "X" Then _
.Resize(1, 2).Cut .Offset(0, -1)
End With '.Cells(lRow)
End With 'rng
Next 'lRow
Debug.Print Format(Timer - dStart, "0.0000") & " sec"
End Sub 'CopyLeft()
--
Garry
Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion