Mor Sagmon
Mor Sagmon

Reputation: 1035

Excel 2016 fails on VBA PasteSpecial

This VBA code is running on Excel 2013 (on multiple different machines):

Sub CopyStaticData()
    Application.ScreenUpdating = False
    Sheets("Data Input").Range("Input_Station_ID").Copy
    Sheets("Data Received").Range("Data_Station_ID").PasteSpecial Paste:=xlPasteValues
    ...

However, on Excel 2016 it throws a runtime error on the last line:

Error 1004: Method 'PasteSpecial' of object 'Range' failed

I tried replacing xlPasteValues with its explicit code (-4163) - to no avail.

Any ideas? A possible Microsoft compatibility issue?

Upvotes: 2

Views: 3126

Answers (1)

Patrick Lepelletier
Patrick Lepelletier

Reputation: 1654

for pasting values only, i recommend not using a copy.

instead, simplify to RangeB.value = RangeA.value.

easier, faster, no tricky clipboard, written in one small line.

Upvotes: 2

Related Questions