+ Reply to Thread
Results 1 to 10 of 10

Calling function from worksheet with nonconcurrent range

  1. #1
    Registered User
    Join Date
    09-26-2007
    Posts
    3

    Calling function from worksheet with nonconcurrent range

    I have a User Defined Function (for finding the next minimum value in a range) that is not working for nonconcurrent ranges when called from within a worksheet. It returns #VALUE!

    This works: =nextmin(A11:A17)
    This does not work: =nextmin(D13,E13,F13,F16)

    However calling the function from within vba works:
    Please Login or Register  to view this content.
    Here is the function:
    Please Login or Register  to view this content.
    If interested, here is the subsequent array sorting function I found (with link to author page):
    Please Login or Register  to view this content.
    Any help is appreciated. Thanks so much.

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    As written, NEXTMIN is returning a Long data type. A spreadsheet can only take Double.
    Please Login or Register  to view this content.
    will take care of that.

    In general though, it seems that NEXTMIN is doing something that could also be done by the spreadsheet funtions RANK or SMALL.

    Using spreadsheet functions (even in fearsome combinations) is usualy faster than using UDFs.

  3. #3
    Forum Contributor
    Join Date
    07-05-2007
    Location
    Lexington, MA
    Posts
    302
    Please Login or Register  to view this content.
    Last edited by FrankBoston; 09-26-2007 at 03:39 PM.
    FrankBoston is the pen name for Andrew Garland, Lexington MA

  4. #4
    Registered User
    Join Date
    09-26-2007
    Posts
    3
    Thanks for your posts.

    mikerickson - I tried your suggestion, but it didn't work. I would rather use an excel function too, but couldn't get one to work for what the user wanted from their spreadsheet. They want the next to smallest number from a range of nonconcurrent cells. And, they will be adding more to this spreadsheet...

    FrankBoston - I believe you hit the problem right on the nose. If there was a Range Excel function as in vba, adding that to the function call would work.

    Thanks again & please add any suggestion if you have them.

  5. #5
    Valued Forum Contributor
    Join Date
    04-11-2006
    Posts
    407
    So this doesn't work for you?
    =SMALL((D13,E13,F13,F16),2)

  6. #6
    Forum Contributor
    Join Date
    07-05-2007
    Location
    Lexington, MA
    Posts
    302
    Believe it or not.
    Please Login or Register  to view this content.

  7. #7
    Valued Forum Contributor
    Join Date
    04-11-2006
    Posts
    407
    Just FYI... using:

    =nextmin((D13,E13,F13,F16))

    gives different results compared to:

    =small((D13,E13,F13,F16),2)

    1.) "Small" does not count blank cells, whereas "Nextmin" reads them as zero.
    2.) "Small" reads each entry as an individual entry, "Nextmin" counts duplicates as one (i.e. if you have: 1,1,2,3,5 - Nextmin returns 2, small returns 1).

  8. #8
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    Hmm..The only way that I was able to pass a discontinous range to a UDF (from the spreadsheet) was to treat it as a paramater array. This function takes a multiple range input and fills arrayofValues with the values of those cells.
    From arrayOfValues to your answer should be just a matter of sorting.

    Please Login or Register  to view this content.
    If your function needs to accept numerical inputs, the split between TypeName="Range" and IsNumeric should take place inside the i loop, before the For Each oneCell loop.
    Last edited by mikerickson; 09-26-2007 at 06:27 PM.

  9. #9
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    This should find the second lowest value in one pass, without going through the sort.
    Please Login or Register  to view this content.
    It will accept values as well as ranges and reads an empty cell as 0.

  10. #10
    Registered User
    Join Date
    09-26-2007
    Posts
    3
    FrankBoston - thank you, the extra parenthesis make my function work ;>)

    Ikaabod - Ahhh very nice. I did not know of the SMALL function. Works like a champ, thank you.

    mikerickson - Thanks for the code, I will definitely try it out.

    Thanks again for all of your help. Much appreciated.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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