Although it actually copies and pastes from one workbook or sheet to another, I keep getting the runtime error 1004: Pastespecial function of range class failed.
The code below does the task, but I still receive the error. I'm sure there is a better way to write the code, but I'm still very new and learning. What can I do to make things better?
Sub CopyWorksheet()
Dim x As Workbook
Dim y As Workbook
Dim ws1 As Worksheet
Dim ws2 As Worksheet
'## Open both workbooks first:
Set x = Workbooks.Open("C:\Users\KimBush\Documents\NP Credentials Project\Greater than 30 days project\Macro Testing\NPPIndependentStatusReport")
Set y = Workbooks.Open("C:\Users\KimBush\Documents\NP Credentials Project\Greater than 30 days project\Macro Testing\DKC-IKC NP Credentialing Update Testing")
'Now, copy what you want from x:
x.Sheets("Sheet1").Range("A1:P10781").Copy
Set ws1 = x.Sheets("Sheet1")
Set ws2 = y.Sheets("Source")
ws1.Cells.Copy ws2.Cells
'y.Close True
'x.Close False
'Now, paste to y worksheet:
y.Sheets("Source").Range("A1").PasteSpecial
'Close x:
'x.Close
End Sub