Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copying Cells in Excel from C#

Status
Not open for further replies.

Smitty020

MIS
Jun 1, 2001
152
US
I have created a program which develops an Excel spreadsheet with data. I wish to create a function that copies the values from a range of cells, and pastes them (just the values) to another range.

I believe that I need to use the Range.Copy and PasteSpecial function, but I am unsure of the syntax.

The range I want to copy is ("A1:F1")
and I want to paste it to ("A10:F10")

Could someone please help me out with the syntax? Again, I need to copy "only the values" from the first range.


Thanks for your help!!!

-Smitty
 
Let be an workshhet object:
Excel._Worksheet m_WorkSheet;
Solution 1:
You can access each cell on row r , column c like m_WorkSheet.Cells[r,c] and you can write your proper copy function.
Solution 2:
Using Excel.Range :

string vCellID="A" + r.ToString();
Excel.Range m_Range = m_WorkSheet.get_Range(vCellID,System.Reflection.Missing.Value);
string vCellValue=m_Range.get_Value(System.Reflection.Missing.Value);
...
m_Range=m_Range.Next;

-obislavu-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top