Reputation: 1
I have the following formula that searches for rows with the text 'Completed' in collumn C on 'Live and pipeline'sheet. if that condition is met, cut and paste the whole row to the 'Completed' Sheet in the same workbook. There should be no empty rows in Sheet1 after this procedure.
At the moment I am getting Application Run time error 1004, Application defined or object defined error
on line Selection.Cut Shift:=xlUp
. The whole code is in Module1. Can anyone tell me what's gone wrong here?
Sub Completed_Projects()
'
' Move completed projects to the Completed Tab
'
' Search until an empty cell is reached
Dim Row As Integer
Row = Range("Total_Completed").Row
Dim SumRow As Integer
Application.ScreenUpdating = False
For Each Cell In ActiveSheet.Range("C8:C100").Cells
If Cell.Value = "Completed" Or Cell.Value = "Aborted" Then
Rows(Cell.Row).Select
Selection.Cut Shift:=xlUp
' Paste Selection
Reference = "A" & Row
Application.Goto (ActiveWorkbook.Sheets("Completed").Range(Reference))
Range(Reference).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
ActiveSheet.Paste
' Update Counters and go back to Live sheet
Sheets("Live and pipeline").Select
Row = Row + 1
End If
Next Cell
Application.ScreenUpdating = True
'
End Sub
Upvotes: 0
Views: 4973
Reputation: 12489
How about this? I've cleaned your code up a bit.
Sub Completed_Projects()
Dim rw As Integer, counter As Integer
counter = Range("Total_Completed").Row
Application.ScreenUpdating = False
For rw = 100 To 8 Step -1
If Worksheets("Live and Pipeline").Range("C" & rw) = "Completed" Or Worksheets("Live and Pipeline").Range("C" & rw) = "Aborted" Then
Rows(rw).Copy Destination:=Worksheets("Completed").Range("A" & counter)
Rows(rw).EntireRow.Delete Shift:=xlUp
counter = counter + 1
End If
Next rw
Application.ScreenUpdating = True
End Sub
Upvotes: 1