Trouble cutting and pasting a range of cells from one worksheet to another.

HarryJT

New Member
Joined
Jul 21, 2021
Messages
7
Office Version
  1. 365
Platform
  1. Windows
I have used and adapted code from another thread on the site however there was errors regarding the size of copy and paste due to using EntireRow. On one sheet I have a data validation list of either outstanding or completed with the aim for excel to cut and paste the row to the "Done" worksheet at the bottom of the exisiting database. The existing code I have reads as follows.

Sub fromOutstanding()
' Move rows from Outstanding to Completed If Column K has a Completed in it.
lastrow = Worksheets("To Do").UsedRange.Rows.Count
lastrow2 = Worksheets("Done").UsedRange.Rows.Count
If lastrow2 = 1 Then
lastrow2 = 0
Else
End If

Do While Application.WorksheetFunction.CountIf(Range("K1:K"), "Completed") > 0
Set Check = Range("K1:K" & lastrow)
If Cell = "Completed" Then
For Each Cell In Checkn
Cell.Range("A:K").Copy Destination:=Worksheets("Done").Range("A" & lastrow2 + 1)
Cell.Range("A:K").Delete
lastrow2 = lastrow2 + 1
Else:
End If
Next
Loop

End Sub

Any help would be appreciated :)
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Hi & welcome to MrExcel.
How about
VBA Code:
Sub HarryJT()
   With Sheets("To Do")
      .Range("A1:K1").AutoFilter 11, "Completed"
      .AutoFilter.Range.Offset(1).Copy Sheets("Done").Range("K" & Rows.Count).End(xlUp).Offset(1, -10)
      .AutoFilterMode = False
   End With
End Sub
 
Upvote 0
Solution
Hi & welcome to MrExcel.
How about
VBA Code:
Sub HarryJT()
   With Sheets("To Do")
      .Range("A1:K1").AutoFilter 11, "Completed"
      .AutoFilter.Range.Offset(1).Copy Sheets("Done").Range("K" & Rows.Count).End(xlUp).Offset(1, -10)
      .AutoFilterMode = False
   End With
End Sub
I have inputted what you suggested however it says in the third (longest) line that there is an application defined or object defined error? I have double checked to make sure I have inputted correctly
 
Upvote 0
Is your data in a structured table or just a normal range?
 
Upvote 0
I believe "To Do" is normal and "Done" is a table having inspected
 
Upvote 0
That should not be a problem, are either of the sheets protected?
 
Upvote 0
That should not be a problem, are either of the sheets protected?
Not to my knowledge, no. I have attached a screenshot of the VBA if that helps.
1626867218715.png
 
Upvote 0
Difficult to tell from an image but it looks as though you have x1Up rather than xlUp. It should be a lower case L
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,186
Members
449,071
Latest member
cdnMech

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top