+ Reply to Thread
Results 1 to 10 of 10

Function to Return Array of Unique Entries in a Range

  1. #1
    Registered User
    Join Date
    09-03-2009
    Location
    Red Bank, NJ
    MS-Off Ver
    Excel 2010
    Posts
    55

    Function to Return Array of Unique Entries in a Range

    I have attached a spreadsheet with a UDF to identify unique entries in a range and return an array of only those uniques. However, the function does not work when passed a Named Range, defined by formula (See the Name Manager). It works fine when passed an explicit range reference or an explicitly defined Named Range.

    I'm open to better solutions to the problem of returning an array of uniques from a list which may include duplicates. Ideally, any solution needs to be able to handle named ranges defined by formula.

    I'm would really like help in fixing my function, improving the speed of my function, or an alternative approach which accomplishes the same thing.

    Thank you
    Attached Files Attached Files

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Function to Return Array of Unique Entries in a Range

    See if the functions I posted here helps. http://www.excelforum.com/excel-prog...o-another.html

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Function to Return Array of Unique Entries in a Range

    Hi avrSiron,

    I'd first try to make your UDF's Volatile. That might make them recalculate in the DNR.

    See http://msdn.microsoft.com/en-us/libr...ffice.15).aspx

    If making your UDF volatile didn't work, I'd then look to not using UDFs in the DNRs. Have you tried Count() or some other functions in your DNRs?
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Function to Return Array of Unique Entries in a Range

    Try something like:
    =IF(SUM(1/COUNTIF(ExplicitName,ExplicitName))<ROW(A1),"",INDEX(ExplicitName,MATCH(0,COUNTIF(D$6:D6,ExplicitName),0)))
    as an array formula (confirm with ctrl+shift+enter) in D7 and copy down. You could also use IFERROR to shorten it in later versions of excel:
    =IFERROR(INDEX(ExplicitName,MATCH(0,COUNTIF(D$6:D6,ExplicitName),0)),"")

  5. #5
    Registered User
    Join Date
    09-03-2009
    Location
    Red Bank, NJ
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: Function to Return Array of Unique Entries in a Range

    Making the UDFs volatile didn't work. Open to suggestions regarding a combination of standard Excel functions that will return the last non-empty row in a column.

  6. #6
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Function to Return Array of Unique Entries in a Range

    Edit: rereading the question, I tested:
    =IF(SUM(1/COUNTIF(RI_LocationConcatList,RI_LocationConcatList))<ROW(A1),"",INDEX(RI_LocationConcatList,MATCH(0,COUNTIF(D$6:D6,RI_LocationConcatList),0)))

    and it also seemed to work ok.

  7. #7
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Function to Return Array of Unique Entries in a Range

    Look at

    http://www.ozgrid.com/Excel/DynamicRanges.htm

    for lots of options.

  8. #8
    Registered User
    Join Date
    09-03-2009
    Location
    Red Bank, NJ
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: Function to Return Array of Unique Entries in a Range

    I appreciate all the feedback, but the issue is what happens to the Application.Caller properties when a DNR is passed to my function. Application.Caller.Address only returns the upper left cell in these instances, instead of the entire range. Accordingly, both row count and column count will be 1. If you put a breakpoint on the With Application Caller line, you will be able to see the issue. Any thoughts?

  9. #9
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Function to Return Array of Unique Entries in a Range

    Hi,

    If you select a range of cells you can tell how many rows and columns are in the range using the Rows.Count and Columns.Count methods.

    Run this code to see what I mean:
    Sub RangeSize()

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    09-03-2009
    Location
    Red Bank, NJ
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: Function to Return Array of Unique Entries in a Range

    The problem is that my UDF (see attached file) is entered as an array function (S-C-E). I use Application.Caller to obtain info about the output range. For some reason, when a DNR is passed to my function Application.Caller.Address only returns the upper left cell, instead of the entire range. Similarly, both Application.Caller.Rows.Count and Application.Caller.Columns.Count return 1.

    The attached workbook shows the function's behavior with different types of range arguments (See column headings). If you put a breakpoint on the With Application Caller line, you will be able to see the issue.

+ 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. [SOLVED] &amp;quot;COUNTU&amp;quot; function in Excel to count unique entries in a range
    By WayneL in forum Excel Formulas & Functions
    Replies: 18
    Last Post: 09-06-2005, 06:05 AM
  2. "COUNTU" function in Excel to count unique entries in a range
    By WayneL in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 09-06-2005, 03:05 AM
  3. "COUNTU" function in Excel to count unique entries in a range
    By WayneL in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 09-06-2005, 02:05 AM
  4. [SOLVED] "COUNTU" function in Excel to count unique entries in a range
    By WayneL in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 09-05-2005, 11:05 PM
  5. [SOLVED] "COUNTU" function in Excel to count unique entries in a range
    By WayneL in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 09-05-2005, 10:05 PM

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