Range offsets and #VALUE! error

C

c.m.valdivia

I'm new to making Automation Add-ins for Excel so this may be trivial...

I'm trying to create an Excel offset function (using Automation) that takes
an offset in rows and columns and a value and prints that value in the offset
cell and the cell from which the function is called. I can get one or the
other, but not both. When I set the off set cell's Value2 property to the
specified value, the original cell returns a wierd #VALUE! error. This
doesn't seem right to me. Shouldn't the offSet cell display the correct value
as a side effect of the function call and the original cell display the
correct value due to the return of the function?

My code is below, I'm developing in Visual Studio 2005 and my project is
otherwise default. Any answers?

// test offsetting
// keep getting wierd error in selected cell
//
public double xyOffset(int xOff, int yOff, double val)
{

Excel.Application excelApp = (Excel.Application)applicationObject;
Excel.Range cell = excelApp.ActiveCell;

// testing to see how get_Offset works

Excel.Range offCell = cell.get_Offset(yOff, xOff);
// return val; // works up to this point.

// works up to this point.
// this is how set values of cells?
offCell.Value2 = val;
return val; /* At this point will display val in
* offset properly but will display #VALUE#
* in the initial selected field.
*/
}
 

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