Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
oops sorry, please corrected "CIT291" with "CIT291_History"
isabelle |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Thursday, September 22, 2016 at 6:22:24 PM UTC-7, isabelle wrote:
oops sorry, please corrected "CIT291" with "CIT291_History" isabelle made adjustments so the cut/paste operates properly, but still the code ENDS after the insert command and I CANNOT FIGURE OUT WHY Sub MoveDone() Dim i As Long, ii As Long, Start As Long ii = LastRow(Worksheets("CIT291_History")) 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 Worksheets("cit291_history").Rows(ii + 1).Insert , Shift:=xlDown ii = ii + 1 End If Next i End With End Sub |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
Am Fri, 23 Sep 2016 09:13:45 -0700 (PDT) schrieb Matthew Dyer: made adjustments so the cut/paste operates properly, but still the code ENDS after the insert command and I CANNOT FIGURE OUT WHY try: Sub MoveDone() Dim i As Long, LRow As Long With Worksheets("CIT291") LRow = .Cells(.Rows.Count, "A").End(xlUp).Row For i = LRow To 2 Step -1 If UCase(.Cells(i, 1).Value) = "DONE" Then .Rows(i).Copy _ Sheets("CIT291_History").Cells(Rows.Count, 1).End(xlUp)(2) .Rows(i).Delete End If Next i End With End Sub Regards Claus B. -- Windows10 Office 2016 |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
this is so bizzare. I've tried the .copy/.paste/.delete, I've tried the .cut/.insert, both attempts have the code stop executing after the destination (paste/etc) runs...
On Friday, September 23, 2016 at 9:25:22 AM UTC-7, Claus Busch wrote: Hi, Am Fri, 23 Sep 2016 09:13:45 -0700 (PDT) schrieb Matthew Dyer: made adjustments so the cut/paste operates properly, but still the code ENDS after the insert command and I CANNOT FIGURE OUT WHY try: Sub MoveDone() Dim i As Long, LRow As Long With Worksheets("CIT291") LRow = .Cells(.Rows.Count, "A").End(xlUp).Row For i = LRow To 2 Step -1 If UCase(.Cells(i, 1).Value) = "DONE" Then .Rows(i).Copy _ Sheets("CIT291_History").Cells(Rows.Count, 1).End(xlUp)(2) .Rows(i).Delete End If Next i End With End Sub Regards Claus B. -- Windows10 Office 2016 |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
Am Fri, 23 Sep 2016 09:53:47 -0700 (PDT) schrieb Matthew Dyer: this is so bizzare. I've tried the .copy/.paste/.delete, I've tried the .cut/.insert, both attempts have the code stop executing after the destination (paste/etc) runs... your function returns always 1 because your looking for anything with "*". Your have to search for "". Change the function to: Function LastRow(sh As Worksheet) LastRow = sh.Range("A:A").Find(What:="", _ After:=sh.Range("A1"), LookIn:=xlValues).Row End Function Regards Claus B. -- Windows10 Office 2016 |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Claus,
Totally appreciate your help. That lastrow function wasn't the issue ("*" is the wildcard to look for anything [value, formula, etc]) and I've been using it as is for years on a variety of projects. One thing I didn't check is the data that I was using. I was working off a workbook someone else sent to me and didn't realize the data was in table form and likewise had other formatting issues that made everything go kablooey. After copy/pasting all of the data into a completely virgin workbook, the codes (all of the versions submitted) works flawlessly. Thank you again for all of your guys' help! On Friday, September 23, 2016 at 10:08:23 AM UTC-7, Claus Busch wrote: Hi, Am Fri, 23 Sep 2016 09:53:47 -0700 (PDT) schrieb Matthew Dyer: this is so bizzare. I've tried the .copy/.paste/.delete, I've tried the .cut/.insert, both attempts have the code stop executing after the destination (paste/etc) runs... your function returns always 1 because your looking for anything with "*". Your have to search for "". Change the function to: Function LastRow(sh As Worksheet) LastRow = sh.Range("A:A").Find(What:="", _ After:=sh.Range("A1"), LookIn:=xlValues).Row End Function Regards Claus B. -- Windows10 Office 2016 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Loop never ends | Excel Programming | |||
Loop never ends | Excel Programming | |||
Loop never ends | Excel Programming | |||
Loop never ends | Excel Programming | |||
Loop ends early | Excel Programming |