View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
isabelle isabelle is offline
external usenet poster
 
Posts: 99
Default loop ends unexpectedly before finishing loop

hi Matthew Dyer,

Sub MoveDone()
Dim i As Long, Start As Long
With Worksheets("CIT291")
Start = LastRow(Sheets(.Name))
For i = Start To 2 Step -1
If UCase(.Range("A" & i).Value) = "DONE" Then
.Rows(i).Cut
.Rows(Start + 1).Insert , Shift:=xlDown
End If
Next i
End With
End Sub

isabelle

Le 2016-09-22 Ã* 20:01, Matthew Dyer a écrit :
Sub MoveDone() Dim i As Integer, ii As Integer Worksheets("CIT291").Activate
For i = LastRow(ActiveSheet) To 2 Step -1 With Range("a" & i) If
UCase(.Value) = "DONE" Then Rows(i).Cut
Sheets("CIT291_History").Rows(LastRow(Worksheets(" CIT291_History")) + 1) End
If End With Next i End Sub

when the true event occurs, the cut/paste functions properly, but then the
code ends. I cannot for the life of me figure out why. there is no other code
in the module other than the lastrow() function. Here's the lastrow()
function I'm using:

Function LastRow(sh As Worksheet) LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _ Lookat:=xlPart, _ LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _ SearchDirection:=xlPrevious, _
MatchCase:=False).Row

End Function