+ Reply to Thread
Results 1 to 6 of 6

User defined function takes array as argument but won't work with range

  1. #1
    Registered User
    Join Date
    09-18-2012
    Location
    San Francsico
    MS-Off Ver
    Excel 2003
    Posts
    6

    User defined function takes array as argument but won't work with range

    Hello,
    I wrote a function that takes a few arguments (two of which are arrays) and returns a value. Sometimes, I would rather use this function by highlighting cells in a sheet but I get a #Value error everytime I try. Does anybody know how to write a function that can take either a range or an array as an argument?

    Please Login or Register  to view this content.
    This is as far as it gets

  2. #2
    Registered User
    Join Date
    09-18-2012
    Location
    San Francsico
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: User defined function takes array as argument but won't work with range

    I guess the question could be simplified to this:

    Please Login or Register  to view this content.
    How do I make it work for either a range or an array of values passed from another function?

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: User defined function takes array as argument but won't work with range

    Hello BuffaloFan32,

    Here is the method I would use. First it validates if the passed argument is a Range or an Array. If it is neither then an error message is displayed and the macro exits. Otherwise the code runs the code for either a Range or an Array.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Registered User
    Join Date
    09-18-2012
    Location
    San Francsico
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: User defined function takes array as argument but won't work with range

    Thank you Leith, that worked great!

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: User defined function takes array as argument but won't work with range

    Hello BuffaloFan32,

    You're welcome.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: User defined function takes array as argument but won't work with range

    Another way:

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

+ 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. Cannot get User Defined Function to work
    By spike1988 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-10-2013, 06:22 PM
  2. User Defined Function to work as calculator
    By SAGAR KHOLLAM in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-18-2012, 07:31 AM
  3. my user defined function doesn'work
    By an61sa in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-21-2012, 01:50 PM
  4. [SOLVED] Excel - User Defined Function Error: This function takes no argume
    By BruceInCalgary in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-18-2006, 04:05 PM
  5. Function (array argument, range argument, string argument) vba
    By Witek in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-24-2005, 11:07 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