PC Review


Reply
Thread Tools Rate Thread

Copy Range including Formats and Forumulas

 
 
=?Utf-8?B?QUxW?=
Guest
Posts: n/a
 
      23rd Feb 2007
We are trying to copy a Range to another worksheet in a C# Excel 2007 add-in
and want to get everything from the source range, including the cell formats
and formulas.

Our code is:

Excel.ListObject inTable -- is passed to the function

Excel.Range drange = inWorksheet.get_Range("A1", Type.Missing);
Excel.Range tableRange = drange;
Excel.ListColumn lcolumn = inTable.ListColumns[column];
lcolumn.Range.Copy(drange);
Excel.Range trange = drange.get_Resize(lcolumn.Range.Count, 1);
tableRange = inTable.Application.Union(tableRange, trange, Type.Missing,
Type.Missing,Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing,


The result of the copy has only the values from the source range.

Thanks.
 
Reply With Quote
 
 
 
 
=?Utf-8?B?QUxW?=
Guest
Posts: n/a
 
      23rd Feb 2007
We found the cause for this...a call to set the range style in another
function was messing up the copy.

"ALV" wrote:

> We are trying to copy a Range to another worksheet in a C# Excel 2007 add-in
> and want to get everything from the source range, including the cell formats
> and formulas.
>
> Our code is:
>
> Excel.ListObject inTable -- is passed to the function
>
> Excel.Range drange = inWorksheet.get_Range("A1", Type.Missing);
> Excel.Range tableRange = drange;
> Excel.ListColumn lcolumn = inTable.ListColumns[column];
> lcolumn.Range.Copy(drange);
> Excel.Range trange = drange.get_Resize(lcolumn.Range.Count, 1);
> tableRange = inTable.Application.Union(tableRange, trange, Type.Missing,
> Type.Missing,Type.Missing, Type.Missing, Type.Missing, Type.Missing,
> Type.Missing,
>
>
> The result of the copy has only the values from the source range.
>
> Thanks.

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I copy a range in Excel without including hidden rows? Lang Microsoft Excel Misc 1 22nd Feb 2008 02:48 PM
Copy and past ... and maintain all formats including column widths JERRY Microsoft Excel Discussion 2 21st May 2007 02:29 AM
VBA Copy a range with Formats & Vaues Only =?Utf-8?B?amlueA==?= Microsoft Excel Programming 4 10th May 2007 03:50 PM
Copy Range / Including Adjacent Cells - into Existing Worksheet. loadbuckets@comcast.net Microsoft Excel Programming 1 14th Jan 2007 12:47 PM
copy range and formats to new workbook Ole Microsoft Excel Programming 0 18th May 2005 08:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:19 AM.