473,401 Members | 2,146 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,401 software developers and data experts.

Excel range in C#

I am rewriting my vba routines to C# to increase speed. I have been unable to
find any help on how to pass ranges to C#.

Excel function that was called in VBA
=CalcRows(A1,A2,B1:B140,C1:C140,D1:D140)

A1 holds the type of calculation to perform
A2 holds the number of rows to calculate
B1:B140 column used in calculations (Dependent on what A1 has)
C1:C140 column used in calculations (Dependent on what A1 has)
D1:D140 columnused in calculation on B1:B140 or C1:C140
CalcRows would then return the total from the calculation.

In VBA I was able to declare a multi dimensional array as a parameter to
hold the three ranges. I have been unable to do this in C#. I reccieve a
#value error in just trying to use a multidimensional array. Ive even try to
use three spearate arrays without any luck.

How do I pass a range or ranges to C#?
Nov 16 '05 #1
2 3568
Check out a previous post for some examples of the Excel object model:
http://msdn.microsoft.com/newsgroups...8a7&sloc=en-us

You'll essentially need to get Excel.Range objects from the Excel.Worksheet
object with a call to Excel.Worksheet.get_Range(string, string);

Hope that helps,
Patrick Altman
"Jerry" wrote:
I am rewriting my vba routines to C# to increase speed. I have been unable to
find any help on how to pass ranges to C#.

Excel function that was called in VBA
=CalcRows(A1,A2,B1:B140,C1:C140,D1:D140)

A1 holds the type of calculation to perform
A2 holds the number of rows to calculate
B1:B140 column used in calculations (Dependent on what A1 has)
C1:C140 column used in calculations (Dependent on what A1 has)
D1:D140 columnused in calculation on B1:B140 or C1:C140
CalcRows would then return the total from the calculation.

In VBA I was able to declare a multi dimensional array as a parameter to
hold the three ranges. I have been unable to do this in C#. I reccieve a
#value error in just trying to use a multidimensional array. Ive even try to
use three spearate arrays without any luck.

How do I pass a range or ranges to C#?

Nov 16 '05 #2
I have figured out that I will need to use the Excel. Object property. THe
problem I am having now is how is the code written for something like this. I
am new to C# and have a few functions I am trying to convert. For instance
how would this be wrriten in C#

Excel cell =calctotal(5,A1:A8,B1:B8)

the five is how many rows to calculate even though more rows are sent.
I have been able to write a function to calculate when a single cell is
sent but when it comes to range I am having problems figuring this out.

Nov 16 '05 #3

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:
Hello, I have a routine in my Windows application that exports the contents of a datagrid to Excel. It is modeled closely after the HowTo example on MSDN: http://tinyurl.com/5g2jm. Depending...
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...
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...
10
by: Esmael | last post by:
Hi to all, /*****************************/ OS-WIn XP SP2 VB6 SP6 /*****************************/ Is their anyone who can help me with this: Source code written on VB6.
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.