Excel Automation

L

leon800219

Hi all,

The following code snippet will insert a row above the first empty
row, and then copy the above row contents to the newly inserted row.
The problem is when the last line was invoked, the value "ASDF"
applies to the entire row instead of only the first cell, and when I
apply the value to offset(0, >n) I got an execption "0x800A03EC". How
can I set value to specific cell in the newly inserted row?


range = oSheet.get_Range("A1", Missing.Value);
range = range.get_End(Excel.XlDirection.xlDown).get_Offset(1,
0);
range.EntireRow.Insert
Excel.XlInsertShiftDirection.xlShiftDown,
Excel.XlInsertFormatOrigin.xlFormatFromLeftOrAbove);
// Move range to the above row, then copy it to the newly inserted
row
range = range.EntireRow.get_Offset(-1, 0);
range.get_Offset(-1, 0).Copy(range);
range.Cells.get_Offset(0, 0).set_Value(Missing.Value, "ASDF");



Thanks,
 
B

broro183

hi Leon,

I'm unfamiliar with "get_offset" & "set_value" but think the line could work
if changed from
"range.Cells.get_Offset(0, 0).set_Value(Missing.Value, "ASDF");"
to
"range.Cells.get_Offset(0, 0).resize(1,1).set_Value(Missing.Value, "ASDF");"

hth
Rob

__________________
Rob Brockett
NZ
Always learning & the best way to learn is to experience...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top