473,320 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Problems Passing Excel Range

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.
Nov 16 '05 #1
4 5205
Using a range like this is usually a bad thing. Why don't you pass the
actual values?

--
http://ManagedXLL.net/
Replace MSDN with my first name when replying to my email address!

"Jerry" <Je***@discussions.microsoft.com> wrote in message
news:60**********************************@microsof t.com...
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.

Nov 16 '05 #2
Using a range like this is usually a bad thing. Why don't you pass the
actual values?

--
http://ManagedXLL.net/
Replace MSDN with my first name when replying to my email address!

"Jerry" <Je***@discussions.microsoft.com> wrote in message
news:60**********************************@microsof t.com...
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.

Nov 16 '05 #3
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.
"Jens Thiel" wrote:
Using a range like this is usually a bad thing. Why don't you pass the
actual values?

--
http://ManagedXLL.net/
Replace MSDN with my first name when replying to my email address!

"Jerry" <Je***@discussions.microsoft.com> wrote in message
news:60**********************************@microsof t.com...
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.


Nov 16 '05 #4
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.
"Jens Thiel" wrote:
Using a range like this is usually a bad thing. Why don't you pass the
actual values?

--
http://ManagedXLL.net/
Replace MSDN with my first name when replying to my email address!

"Jerry" <Je***@discussions.microsoft.com> wrote in message
news:60**********************************@microsof t.com...
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.


Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet...
11
by: Mr. Smith | last post by:
Hello all, My code can successfully open, write to, format and save several worksheets in a workbook then save it by a given name, close and quit excel. My problem is that if I try and do it...
8
by: mytfein | last post by:
Hi Everyone, Background: Another department intends to ftp a .txt file from the mainframe, for me to process. The objective is to write a vb script that would be scheduled to run daily to...
4
by: IMS.Rushikesh | last post by:
Hi All, I am trying to execute below code but it gives me an COMException ///// Code Start //// public string GetName(Excel.Range range) { try { if (range.Name != null)
3
by: | last post by:
I wrote a class in VB.NET to export the contents of a datagrid to Excel. It works perfectly on my machine, but it fails on my customers' PCs that have identical versions of Win XP (SP1) and Excel...
1
by: RickH | last post by:
..Cells(1,y).GetType ownly shows instead of .Value, .Copy, etc. The code below is derived from samples, it should work, but I've messed up somewhere... Imports System.Windows.Forms Imports...
2
by: kosecki | last post by:
Hi, I can't find the way to do something from vb .net in current copy of Excel. All posts which I read tell how to make application.excel object and do something. I need to write something like...
7
by: Alan Roberts | last post by:
Can someone please explain the following for me... I am trying to link to a .NET DLL from Excel. Excel needs to pass a reference to itself to the DLL and then the DLL needs to perform some work...
16
by: alexia.bee | last post by:
Hi all, In some weird reason, excel instance won;t die if i remove the comment from 4 lines of setting values into struct. here is a snipcode public...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.