ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to test for valid 'Paste:=xlValues' before attempt. (https://www.excelbanter.com/excel-programming/421186-how-test-valid-paste-%3Dxlvalues-before-attempt.html)

Bassman62

How to test for valid 'Paste:=xlValues' before attempt.
 
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



Brotha Lee

How to test for valid 'Paste:=xlValues' before attempt.
 
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

on error goto 0 'Reset error handling

"Bassman62" wrote:

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



Bernie Deitrick

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

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

HTH,
Bernie
MS Excel MVP


"Bassman62" wrote in message
...
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






All times are GMT +1. The time now is 10:52 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com