Problems Passing Excel Range

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am new to C# and have been trying to figure out how to access a range
passed to C#. I have tried everything I can find and have been unable to get
it to work. Here is a test sample Ive been playing with and It returns an
error. What is wrong with this function?

public int CalcArray(ref int CalcType,ref int Lines,Excel.Range rngFind)
{
double test;
int result;

result = Convert.ToInt32(rngFind.get_Offset(0, 1).Value2);

return result;
}


In excel, I have a cell that "=CalcArray(H4,J7,A3:A5)" to call it. Cell H4,
J7 are numbers. Same with Column A. When the function is called it gets a
#Value error.
 
Using a range like this is usually a bad thing. Why don't you pass the
actual values?
 
That is only a test code Im using to figure out how to pass ranges with
excel. I am in the process of converting VBA functions over to C# and the
function I need this for I have it setup to pass 2 values and it needs to
pass three ranges that are approximately 90 rows each. SSo passing values
would not work. I am trying to do this all in C# and trying to avoid VBA
wrapper if possible. The main intention is for increasing speed in the
spreadsheet.
 
Back
Top