Manual Ctrl+C to copy from excel, VBA to paste values in specific range in different workbook (Getting 1004 error)

xlyfe

Board Regular
Joined
Aug 28, 2020
Messages
53
Office Version
  1. 365
Platform
  1. Windows
Hello,
I've been struggling with this for hours now.
I believe the solution is simple, but I can't figure it out.
The complete steps being taken are as follows...
  1. Open external workbook
  2. Manually select range (which varies often)
  3. Press Ctrl+C or right click select Copy, to copy selected range to windows clipboard
  4. Open workbook where VBA button resides to paste values from clipboard into
  5. Press button
  6. Get error
This is the code that is giving me a (Run-time error '1004': Method 'Range' of object '_Global' Failed).
I've noted below which line is producing this error.

VBA Code:
Sub PstFlatBtn_Click()
Application.ScreenUpdating = False
Application.Calculation = xlManual
    Range("FlatsPaste").PasteSpecial xlPasteValues   'getting the 1004 error here
    Range("FlatsAutoFit").Columns.AutoFit
    Range("EwpAutoFit").Columns.AutoFit
    Range("SidingAutoFit").Columns.AutoFit
    Range("CustomerAutoFit").Columns.AutoFit
Application.Calculation = xlAutomatic
Application.ScreenUpdating = True
End Sub

Is anybody able to help me quickly see what I'm doing wrong here?
I've tried multiple ways of addressing this issue, but none have worked, so I'm starting over.
Please let me know if I need to provide more information to help create a clearer picture of the issue at hand.
Thank you in advance to anybody that is able to assist. 🙏
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
12,618
Office Version
  1. 365
Platform
  1. Windows
It's got to be something from the source file causing this.
This is what is confusing me as well, if it works manually carrying out the exact same process then I can see no reason for it to fail.

What happens if you try running the recorded code that you posted earlier?

What about entering the worksheet range into the code instead of the named range? (Try this with your original code and my edit, although I don't expect any difference).
 

Watch MrExcel Video

Forum statistics

Threads
1,129,530
Messages
5,636,861
Members
416,946
Latest member
mniceguy81

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