View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Cone Jim Cone is offline
external usenet poster
 
Posts: 3,290
Default Copying and Pasting cells within an Add-In

Tom,

Some things to consider...

Is the destination sheet protected?
Is the destination sheet paste range the same size as the copied data or a single cell?
Is the destination sheet hidden? I don't believe you can make a selection
on a hidden sheet.
The easiest way to get data from one range to another is simply:
Range(XYZ).Value = Range(ABC).Value
The paste method uses a "Destination" argument unless you select the
destination range in advance (see above).
Also, take a look at the PasteSpecial method.

Regards,
Jim Cone
San Francisco, CA


"TMesh" wrote in message ...
Hello

I am putting together an Excel Add-In for a client. One function of the
add-in needs to perform is to give the client the capability to save values
entered as default.

So I have a sheet within the add-in to store the values entered.

The Userform uses the Spreadsheet control from the Microsoft Office Web
Components. The following line of code works, which copies a range of cells
in the control to the clipboard:

xlsExpectedStarts.ActiveSheet.Range(xlsExpectedSta rts.ActiveSheet.ViewableRange).Copy

I am getting the following error when I try and paste the contents to the
worksheet to store the defaults.

Run-time error '-2147024809 (80070057)':
Invalid Argument.

I have tried to specify the range to copy to within the copy statement as
follows:

ThisWorkbook.Sheets("shtT1_Default").Range("rngEST _T1")

I have also tried to paste the cells after the copy statement as follows:

shtPaste = ThisWorkbook.Sheets("shtT1_Default").Range("rngEST _T1").Select
shtPaste.Paste

I get the same error message.

I have used the copy statement by itself and the used Ctrl-V to paste the
cells into a new sheet. So it works, but I have not found the right way to
specifiy it in code.

Any help would greatly be appreciated.

Thanks in advance
Tom Meschede