+ Reply to Thread
Results 1 to 9 of 9

Pass variable number of arguments to worksheetfunction

  1. #1
    Forum Contributor
    Join Date
    05-30-2013
    Location
    France
    MS-Off Ver
    2010
    Posts
    260

    Pass variable number of arguments to worksheetfunction

    Hi,

    I have an array with strings "M","P","R" (size of the array varies from 2 to n) which refer to columns. I'm trying to write a procedure/function that will take the array and write the function "=SUM(M3,P3,R3)" to Q3 in this case (formula would need to be visible). Would there be any way to loop inside worksheetfunction.sum(arg1,arg2,arg3 etc.) or with range("Q3").Formula = "=arg1+arg2+arg3 etc."?

    Thanks,
    amphi

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Pass variable number of arguments to worksheetfunction

    Do you mean you want the actual formula to appear as you describe or you just want the sum evaluated and put in Q3? If the former, why do you need it?

  3. #3
    Forum Contributor
    Join Date
    05-30-2013
    Location
    France
    MS-Off Ver
    2010
    Posts
    260
    I'm looking to have the actual formula in the worksheet. I'm distributing the code and need to keep the formula for the other users.

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Pass variable number of arguments to worksheetfunction

    But why is it easier to to use your approach than to just write the formula in the cell?

    Anyway it can be done.

  5. #5
    Forum Contributor
    Join Date
    05-30-2013
    Location
    France
    MS-Off Ver
    2010
    Posts
    260
    Ok thanks good to know. So using something like a lbound/ubound loop to store in a string and the range.value property ?

  6. #6
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Pass variable number of arguments to worksheetfunction

    I can post some code later if nobody else steps in.

  7. #7
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Pass variable number of arguments to worksheetfunction

    So here is one way. You have to call the first procedure from another. Another parameter could be added to specify the location of the formula.
    Please Login or Register  to view this content.
    Last edited by StephenR; 03-17-2016 at 09:06 AM.

  8. #8
    Forum Contributor
    Join Date
    05-30-2013
    Location
    France
    MS-Off Ver
    2010
    Posts
    260

    Re: Pass variable number of arguments to worksheetfunction

    Thanks so much ! With your solution, I understand why the request is a bit "clunky".

  9. #9
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,995

    Re: Pass variable number of arguments to worksheetfunction

    If your question has been answered please mark your thread as "Solved" so that members will know by looking at the thread title that your problem is solved. Go to the menu immediately above your first post to the thread and click on Thread Tools. From the dropdown menu select "Mark this thread as solved..."

    If a member helped you solve your problem, consider adding to their reputation by clicking on the star icon below their name.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. WorksheetFunction.Match returns error with String variable, but not with number
    By IntisarN in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-20-2015, 03:38 PM
  2. [SOLVED] Worksheetfunction.match arguments causing function to fail
    By icyrius in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-13-2013, 09:26 AM
  3. user defined function I can't pass the arguments
    By Deci in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-26-2010, 09:33 AM
  4. [SOLVED] small fuction problem pass arguments
    By ina in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-25-2006, 08:30 AM
  5. How to pass arguments to vlookup in VBA
    By mathewg in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-20-2006, 08:34 AM
  6. Passing Variable Number of Arguments to a Sub
    By blatham in forum Excel General
    Replies: 4
    Last Post: 12-10-2005, 06:36 AM
  7. Run/execute VBS and pass arguments
    By Claud Balls in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-04-2005, 05:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1