![]() |
Excel Automation
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, |
Excel Automation
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... " wrote: 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, |
All times are GMT +1. The time now is 03:34 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com