troubleshooting Question

Moving rows between Excel worksheets using VBA

Avatar of Paul Richards
Paul Richards asked on
VBAMicrosoft ExcelMicrosoft Office
11 Comments3 Solutions121 ViewsLast Modified:
I have created a worksheet to reflect project status. One of the columns is, surprisingly, "Project Status", which calls from a list of values. One of these values is "Completed".
I have two relevant sheets in the workbook, both with identical column structure: one to reflect projects In Flight, and the second to show Completed projects, so my objective is to implement code which would validate the project status cell (column R), and where the value is "Completed" the entire row will be copied to the Completed sheet and then deleted from the In Flight sheet.
I would also need a reverse solution to allow for human error. So in case the status was updated in error and the row moved, the user could then access the "Completed" tab, change the status back to something else other than "Completed" and then the row would be moved back to the In Flight sheet.
The row to be occupied, in either direction would be the next available empty row.
Hope that makes sense to someone...!

I have tried this, and it appears to do more-or-less what I am trying to achieve, but then Excel freezes! I think it is going into a loop somewhere but cannot locate it.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

    Set i = Sheets("InFlight")
    Set e = Sheets("Completed")
    Dim d
    Dim j
    d = 4
    j = 5
    Do Until IsEmpty(i.Range("R" & j))
    If i.Range("R" & j) = "Completed" Then
        d = d + 1
        e.Rows(d).Value = i.Rows(j).Value
    End If
    j = j + 1
End Sub

Open in new window

Roy Cox
Group Finance Manager

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 3 Answers and 11 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros