LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Copy range values in C#

Greetings,

There are several examples of what I am trying to do in this section but
they all appear to use VB. I have an Excel add-in written in C#. One thing
I need to do is copy the values from a range of cells into a different range
of cells in another workbook. Here is the code;


private void Go_Click(object sender, EventArgs e)
{
String strTopSourceCell = "A2", strBottomSourceCell = "A46";
String strTopDestinationCell = "F16", strBottomDestinationCell =
"F60";
Excel.Worksheet activeWorksheet =
(Excel.Worksheet)Globals.ThisAddIn.Application.Act iveSheet;
Excel.Range exrSource =
activeWorksheet.get_Range(strTopSourceCell, strBottomSourceCell);
Globals.ThisAddIn.ThisAddIn_OpenDigiKeyRFQTemplate ();
activeWorksheet =
(Excel.Worksheet)Globals.ThisAddIn.Application.Act iveSheet;
Excel.Range exrDestination =
activeWorksheet.get_Range(strTopDestinationCell, strBottomDestinationCell);
//exrSource.Copy(exrDestination);
//exrSource.Copy();

exrSource.Copy(exrDestination.PasteSpecial(Microso ft.Office.Interop.Excel.XlPasteType.xlPasteValues,
Microsoft.Office.Interop.Excel.XlPasteSpecialOpera tion.xlPasteSpecialOperationNone, true, false));
}

When I use the (commented) line exrSrouce.Copy(exrDestination) I get the
values but the format of the destination is being altered.


When I use the (commented) line exrSrouce.Copy() I get a compiler error - no
overload for range.copy has zero arguments.

The documentation for Range.Copy() said that if the destination argument was
omitted it would copy to the clipboard. If I put null in there I get a run
time error.

I have tried using the Range.PasteSpecial as an argument for copy (the
uncommented line in my code) and it throws a runtime error. I suspect it is
to be used after the clipboard has been loaded.

How do I copy this range to the clipboard and then paste just the values to
the destination range (in C#).

Thanks for your help.

Dale Hoffman
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to copy range and paste as values Tom Joseph Excel Programming 1 March 1st 09 12:16 PM
Copy values in a range to memory rchan11 Excel Programming 1 November 7th 07 04:55 PM
Use a button to copy the values of one range to another SuitedAces[_2_] Excel Programming 3 June 28th 06 05:35 AM
copy / paste values for certain range Eric Dreshfield Excel Programming 2 September 10th 03 04:04 PM
Range COPY function - how to copy VALUES and not formulas James Cooke Excel Programming 1 August 21st 03 07:04 PM


All times are GMT +1. The time now is 11:11 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"