Solved

How to pass multiple parameters to user defined function in excel

Posted on 2009-07-15
1
225 Views
Last Modified: 2012-05-07
Hi Experts,

I am working on an Excel add-in and want to pass multiple parameter to a function which i defined.

for example if i send the parameters as follows it doesn't work.

  public int AddNumbers(params int[] Numbers)
        {
            int Result = 0;
            for (int i = 0; i < Numbers.Length; i++)
            {
                if (i==0)
                {
                    Result = Numbers[i];
                }
                else
                {
                   Result = Numbers[i - 1] + Numbers[i];
                }
               
            }
            return Result;
        }

but if i use the function as follows it works,

        public int Addtest(int a, int b){

            int test = 0;
            try
            {
                test = AddNumbers(new int[] {a,b });
            }
            catch (Exception)
            {
               
                throw;
            }
            return test;
        }

My question is, I have a user defined function in my excel add-in project  and want to pass last parameters as a parameter array not as an optional range.

public object DummyFunction(string strDummy1, string strDummy2, object objDummy, params string[] strInputs)

0
Comment
Question by:Kadakal
1 Comment
 
LVL 1

Accepted Solution

by:
chriswilsonuk earned 500 total points
Comment Utility
I don't think it's possible to pass arrays into Excel functions.

You will need to make this a Range, which is effectively the same thing except it has the potential to have incorrect data types - so you'll need to filter those.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now