+ Reply to Thread
Results 1 to 3 of 3

Unique values depending on variable

  1. #1
    Registered User
    Join Date
    04-13-2004
    Posts
    28

    Unique values depending on variable

    Hi guys,

    I have a problem I can't solve. I have a workbook that has two sheets on it.

    In Sheet 1, cell A2 I have a variable, in this case it's a number 249

    In Sheet 2, I have an annual leave report which shows entries for colleagues with annual leave booked in the future. Due to the fact that a colleague could book more than 1 lot of leave, I'd like the number of unique employee numbers from the variable in Sheet 1, Cell A2.

    The variable in Sheet 1, Cell A2 will be looking for corresponding data from Sheet 2, Column I. The employee numbers are located in Sheet 2, Column A.

    Is this possible ?


    Sheet 2 Data

    ColA Col I

    68917 John Daly 249
    12249 Tiger Woods 249
    68917 John Daly 249
    12249 Tiger Woods 249
    2262 Bill McGrath 249
    68917 John Daly 249
    Last edited by Skybeau; 11-12-2009 at 12:53 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Unique values depending on variable

    Try this:

    =SUM(INDEX((Sheet2!$I$1:$I$7=A6) * (MATCH(Sheet2!$A$1:$A$7, Sheet2!$A$1:$A$7, 0) = ROW($1:$7)), 0))

    The ranges have to match your data range exactly, so adjust them accordingly.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Unique values depending on variable

    JB, I would make the point that using INDEX in this form is generally regarded as being pretty slow - else we'd use all the time in preference to SUMPRODUCT.

    I think also that the above would fail to return correct result if the value in A appeared multiple times but under different codes (ie the MATCH should be conducted against the concatenation of I & A rather than just A) ... I believe also that should any entries in A be blank on Sheet2 then you would get an #N/A error.

    Adopting JB's approach in SUMPRODUCT form with the above taken into account I believe something along the lines of:

    Please Login or Register  to view this content.
    should work... it would of course be easier to have a concatenation column at source, eg:

    Please Login or Register  to view this content.
    Then

    Please Login or Register  to view this content.
    which is as you can see a little less convoluted... but not much
    Last edited by DonkeyOte; 11-12-2009 at 05:26 AM. Reason: typo

+ 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