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

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
65,664
Office Version
  1. 365
Platform
  1. Windows
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
 
Solution

HarryJT

New Member
Joined
Jul 21, 2021
Messages
7
Office Version
  1. 365
Platform
  1. Windows
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
65,664
Office Version
  1. 365
Platform
  1. Windows
Is your data in a structured table or just a normal range?
 

HarryJT

New Member
Joined
Jul 21, 2021
Messages
7
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

Is your data in a structured table or just a normal range?
I believe either both structed tables or "To DO2 may just be a normal range, however unsure
 

HarryJT

New Member
Joined
Jul 21, 2021
Messages
7
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

I believe "To Do" is normal and "Done" is a table having inspected
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
65,664
Office Version
  1. 365
Platform
  1. Windows
That should not be a problem, are either of the sheets protected?
 

HarryJT

New Member
Joined
Jul 21, 2021
Messages
7
Office Version
  1. 365
Platform
  1. Windows
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
65,664
Office Version
  1. 365
Platform
  1. Windows
Difficult to tell from an image but it looks as though you have x1Up rather than xlUp. It should be a lower case L
 

Forum statistics

Threads
1,147,635
Messages
5,742,250
Members
423,717
Latest member
rubthenut

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
Top