Paste Method of Worksheet Class Fail Error

Anaya Zeeshan

New Member
Joined
Nov 4, 2021
Messages
33
Office Version
  1. 365
Platform
  1. Windows
I have written this code to cut rows from worksheet (shUpdated) based on column AB to another worksheet (ShCompleted). It is giving me this error "Paste method of worksheet class failed". here is the code:

Option Explicit

Sub Project_Completed()

Dim LastRow As Long
Dim Rng1 As Range
Dim cell As Range

LastRow = shUpdate.Range("AB" & Rows.Count).End(xlUp).Row
Set Rng1 = shUpdate.Range("AB3", shUpdate.Range("AB" & LastRow))

For Each cell In Rng1
If cell.Value = "Completed" Then
cell.EntireRow.Select
Selection.Delete Shift:=xlUp
ShCompleted.Select
Range("A65536").End(xlUp).Offset(1, 0).Select
ActiveSheet.Paste
shUpdate.Activate

' Sheets("Completed Projects").Select
' Range("A3").Select
' ActiveSheet.Paste

End If
Next cell
End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
At one point you say shUpdated (with a "d" at the end) and in the code it is shUpdate (without a "d")
If that is a sheet name, you have to call it with
Code:
Sheets("shUpdate").Range ........

If not, you have to qualify, something like
Code:
Dim shUpdate As Worksheet
Set shUpdate = Worksheets("SheetNameItRefersTo")
same for all other possible scenarios
 
Upvote 0
It was a typo error in my post. In the code I have used “ShUpdate”. The code works fine till activiating ShCompleted and select next available row and gives error on “Activesheet.paste”
 
Upvote 0
"ShUpdate" with a capital S (Post #3) or as in your first post with a small s?
Are that sheet names?
 
Upvote 0
What are you pasting? I can't see that you have copied anything.

Are the sheets defined outside of the sub?
As pointed out by jolivanes, you would need something like the below to call the sheets in that way:
VBA Code:
Dim ShCompleted As Worksheet
Set ShCompleted = Sheets("Completed Projects")

When deleting rows in a loop it is best to go bottom to top.
 
Upvote 0
Solution
What are you pasting? I can't see that you have copied anything.

Are the sheets defined outside of the sub?
As pointed out by jolivanes, you would need something like the below to call the sheets in that way:
VBA Code:
Dim ShCompleted As Worksheet
Set ShCompleted = Sheets("Completed Projects")

When deleting rows in a loop it is best to go bottom to top.
You were right, I worte cut instead of copy which was giving the error.
Thanks alot :)
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,595
Members
449,089
Latest member
Motoracer88

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