views:

47

answers:

1

Hi,

I have well defined Excel range, let's say "A5:I9" for example. I would like to multiply the complete rows of these range via C#. "Multiply" means to copy the range several times below itself, shifting the rest of the document down. Any hint how to do that? I'm fighting with the Range.Insert and Range.Copy methods for quite some time now and in various combinations, but they never behave like I would expect accoring to the documentation!?

cheers, Achim

A: 

To shift the rest of the document down I guess you would need to insert the expected amount of rows (five in you example) where you want to paste, before each copy:

// First copy paste with static range values
Range destination = yourWorksheet.get_range("A10",Type.Missing)
yourWorksheet.get_range("A5", "I9").Copy(destination);

Then loop on it while keeping the last "written" line.

DrDro