How to test for valid 'Paste:=xlValues' before attempt.

B

Bassman62

I have code that pastes values at the current selection.
This works fine when the 'copy' is within excel.
However, occasionally the source may be from another application in which
case the 'Paste:=xlValues' fails.
Is there a way to test to see if 'Paste:=xlValues' is a valid option before
using it in the following code?
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Thank you.

Dave
 
B

Brotha Lee

Bassman62,

I do not know a solution to check if pastevalues is a valid operation,
however I have the following workaround

on error resume next 'If error occurs while pasting special, go to next lin
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

if err.number <> 0 then
'Paste special could not be performed, perform regular paste
Activesheet.paste
end if
 
B

Bernie Deitrick

Dave,

If Application.CutCopyMode = xlCopy Then
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
End If

HTH,
Bernie
MS Excel MVP
 
Top