+ Reply to Thread
Results 1 to 23 of 23

Find the address of the last Unique Cell in an array

Hybrid View

  1. #1
    Registered User
    Join Date
    12-17-2015
    Location
    London, England
    MS-Off Ver
    2010
    Posts
    27

    Talking Find the address of the last Unique Cell in an array

    I have an array of numbers sorted by ascending date. These numbers are filled when there are blanks with the values from above. eg:


    11/04/2016 1 2 1
    12/04/2016 2 4 2
    13/04/2016 3 6 3
    14/04/2016 4 2 3
    15/04/2016 4 3 3
    16/04/2016 4 9 3

    I need to find the corresponding date of the last unique value (from the bottom up). So 14/04/2016 for Column B for instance.
    I have tried various combinations of index(match,match) and lookup(1,1/Array) methods but no luck. Any thoughts? I unfortunately cannot change the source array at all, only reference it.
    Thanks

  2. #2
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Find the address of the last Unique Cell in an array

    Let's see if I understand this...

    Data Range
    A
    B
    C
    D
    1
    4/11/2016
    1
    2
    1
    2
    4/12/2016
    2
    4
    2
    3
    4/13/2016
    3
    6
    3
    4
    4/14/2016
    4
    2
    3
    5
    4/15/2016
    4
    3
    3
    6
    4/16/2016
    4
    9
    3
    7
    ------
    ------
    ------
    ------


    The date that corresponds to the "last" unique value in column B is 4/14/2016.

    The date that corresponds to the "last" unique value in column C is 4/16/2016.

    The date that corresponds to the "last" unique value in column D is 4/13/2016.

    Is that correct?
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  3. #3
    Registered User
    Join Date
    12-17-2015
    Location
    London, England
    MS-Off Ver
    2010
    Posts
    27

    Re: Find the address of the last Unique Cell in an array

    Spot on Tony. Any ideas? I have the last values already stored so I can use them as inputs (so 4,9,3).

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,286

    Re: Find the address of the last Unique Cell in an array

    Since you have the last values, use

    =INDEX($A:$A, MATCH(XXXX,B:B,False))

    where XXXX is a cell with the last value for B.

    If you need to copy it down instead of to the right, use

    =INDEX($A:$A, MATCH(XXXX,INDEX($B:$Z,ROW(A1)),False))
    Bernie Deitrick
    Excel MVP 2000-2010

  5. #5
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Find the address of the last Unique Cell in an array

    Quote Originally Posted by Bernie Deitrick View Post
    =INDEX($A:$A, MATCH(XXXX,B:B,False))

    where XXXX is a cell with the last value for B.
    That won't necessarily find the correct location.

    For example, in column C there are multiple non-consecutive instances of 2. If 2 was the last value then using INDEX/MATCH would find the first instance from top to bottom.

  6. #6
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Find the address of the last Unique Cell in an array

    Try this...

    Data Range
    A
    B
    C
    D
    E
    F
    G
    1
    4/11/2016
    1
    2
    1
    4
    4/14/2016
    2
    4/12/2016
    2
    4
    2
    9
    4/16/2016
    3
    4/13/2016
    3
    6
    3
    3
    4/13/2016
    4
    4/14/2016
    4
    2
    3
    5
    4/15/2016
    4
    3
    3
    6
    4/16/2016
    4
    9
    3
    7
    ------
    ------
    ------
    ------
    ------
    ------
    ------


    All formulas are array formulas**.

    G1:

    =OFFSET(A$1,ROWS(A$1:A$6)-LOOKUP(1E100,FREQUENCY(IF(B$1:B$6=F1,ROW(B$1:B$6)),IF(B$1:B$6<>F1,ROW(B$1:B$6)))),0)

    G2:

    =OFFSET(A$1,ROWS(A$1:A$6)-LOOKUP(1E100,FREQUENCY(IF(C$1:C$6=F2,ROW(C$1:C$6)),IF(C$1:C$6<>F2,ROW(C$1:C$6)))),0)

    G3:

    =OFFSET(A$1,ROWS(A$1:A$6)-LOOKUP(1E100,FREQUENCY(IF(D$1:D$6=F3,ROW(D$1:D$6)),IF(D$1:D$6<>F3,ROW(D$1:D$6)))),0)

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.

  7. #7
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Find the address of the last Unique Cell in an array

    P.S.

    Format the cells as Date (if needed).

  8. #8
    Registered User
    Join Date
    12-17-2015
    Location
    London, England
    MS-Off Ver
    2010
    Posts
    27

    Re: Find the address of the last Unique Cell in an array

    Thanks Tony, will give it a go on Monday.
    I think a potential problem will be that I instead of referencing direct columns I need to lookup the column reference - so I will need to use something like INDEX(ARRAY, 0, MATCH()) to replace "B$1:B$6" - unsure how to use this in the context of a RANGE:CELL type formula. Much easier in VBA but unfortunately not available in this case.
    So in this case if you can imagine column names in cells E1:E3 and the same column headers replacing B,C&D

  9. #9
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Find the address of the last Unique Cell in an array

    Can you post a SMALL sample file so I can see what we're dealing with?

    Try to make the sample as SMALL as possible. I hate having to scroll all around looking for stuff!

  10. #10
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,286

    Re: Find the address of the last Unique Cell in an array

    That is exactly what he wants - the first instance, of the last cell that has a unique value as the range is extended from B1, one cell down per step. After each step, ask "Is the new cell unique in the extended range?" The last time that question is true is the instance the OP wants, so 9 is the value of interest in the column C.

  11. #11
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Find the address of the last Unique Cell in an array

    This is what I based my formulas on:

    I need to find the corresponding date of the last unique value (from the bottom up).

  12. #12
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Find the address of the last Unique Cell in an array

    The best that I can do is find the date corresponding to the last unduplicated value in the columns. I hope that this helps. So far, I haven't been able to find the value of the last series of duplicates if they exist.
    To find the last unduplicated value in the columns. Enter in destination cell with Ctrl + Shift + Enter and fill across.
    Formula: copy to clipboard
    =INDIRECT("A"&MAX(IF(COUNTIF(B1:B10,B1:B10)=1, ROW(B1:B10))))


    This comes close but fails where the last values are duplicates. if the last value(s) in the column are not duplicated and are unique, this works. Again enter with Ctrl + Shift + Enter
    Formula: copy to clipboard
    =IF(MAX(IF(COUNTIF(B1:B10,B1:B10)=1, ROW(B1:B10))) < COUNTA(A:A),OFFSET($A$1,MAX(IF(COUNTIF(B1:B10,B1:B10)=1, ROW(B1:B10))),0),OFFSET($A$1,MAX(IF(COUNTIF(B1:B10,B1:B10)=1, ROW(B1:B10)))-1,0))
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

  13. #13
    Registered User
    Join Date
    12-17-2015
    Location
    London, England
    MS-Off Ver
    2010
    Posts
    27

    Re: Find the address of the last Unique Cell in an array

    Thanks all - yes that is correct Tony, there are instances where the values are repeated earlier in the data set and the simple index(match,match) method returns those values.
    I will make up a small sample for you and post it in a few minutes. Keep in mind the file I am fetching it from is a CSV that is updated and overwritten daily, hence the need for dynamic references rather than static.

  14. #14
    Registered User
    Join Date
    12-17-2015
    Location
    London, England
    MS-Off Ver
    2010
    Posts
    27

    Re: Find the address of the last Unique Cell in an array

    Attached an example, see the comments in italics. My target is the blue box based on the green values.
    Attached Files Attached Files

  15. #15
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Find the address of the last Unique Cell in an array

    In the sample file you have an incorrect result for Sample C. You have 4/13/2016 when it should be 4/15/2016.

    This array formula** entered in M4:

    =OFFSET(A$3,COUNTA(A$3:A$17)-LOOKUP(1E100,FREQUENCY(IF(INDEX(B$3:H$17,0,ROWS(M$4:M4))=L4,ROW(A$3:A$17)),IF(INDEX(B$3:H$17,0,ROWS(M$4:M4))<>L4,ROW(A$3:A$17)))),0)

    Format as Date

    Copy down as needed

  16. #16
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,286

    Re: Find the address of the last Unique Cell in an array

    You can use a User-Defined-Function in VBA, code below. Enter this formula in M3 and copy down.

    =EarliestDate(A:A,INDEX($B:$H,,ROW(A1)))

    Use this formula in L3, and copy down:

    =INDEX(INDEX($B:$H,,ROW(A1)),COUNTA(INDEX($B:$H,,ROW(A1))))

    Function EarliestDate(rDates As Range, rValues As Range) As Date
        Dim rVal As Range
        Dim Sh As Worksheet
        Dim lR As Long
        
        Set Sh = rValues.Parent
        Set rVal = Sh.Cells(Sh.Rows.Count, rValues.Column).End(xlUp)
        
        For lR = rVal.Row To rValues.Cells(1).Row Step -1
            If Sh.Cells(lR, rValues.Column).Value <> rVal.Value Then
                EarliestDate = rDates.Cells(lR + 1, 1).Value
                Exit Function
            End If
        Next lR
    End Function

  17. #17
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Find the address of the last Unique Cell in an array

    For what it is worth, I will add this in case it will help.
    1. To get the values from columns B, C and D in the order that they appear in the lists. Enter this in G2 and fill across 3 columns total and down until the data runs out.
    Formula: copy to clipboard
    =IFERROR(INDEX(B$1:B$6,MATCH(1,INDEX((COUNTIF(G$1:G1,B$1:B$6)=0)*(B$1:B$6<>""),0),0)),"")

    Enter this array formula (entered with Ctrl + Shift + Enter) in G8 and fill across. (these are the cells that I used, you can use whatever you like by making minor changes to the cell references.
    Formula: copy to clipboard
    =OFFSET(INDEX($A$1:$A$6,LARGE(IF(B$1:B$6=INDEX(G$2:G$6,MATCH(10^300,G$2:G$6)-1),ROW(B$1:B$6),""),1)),1,0)

    What this does is find the second last value in the helper lists. Then the last location of that value is found and offset by 1 row to get the first row of the last value.
    Attached Files Attached Files

  18. #18
    Registered User
    Join Date
    12-17-2015
    Location
    London, England
    MS-Off Ver
    2010
    Posts
    27

    Re: Find the address of the last Unique Cell in an array

    Thanks guys! Much appreciated! Works like a charm. If you are ever in London I owe beers!

  19. #19
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Find the address of the last Unique Cell in an array

    You're welcome. Thanks for the feedback!

  20. #20
    Registered User
    Join Date
    12-17-2015
    Location
    London, England
    MS-Off Ver
    2010
    Posts
    27

    Re: Find the address of the last Unique Cell in an array

    Hi Tony, slight extension to this problem - is there a way to overcome blanks in the array at the bottom of the list? (Applies to the two ROW functions). In the example I sent earlier if you delete C16 for instance then the formula returns 00/01/1990 (FALSE or 0).
    I have tried to hack at it but having no luck. Basically the value of A$16 in ROW needs to find the last non-blank cell in the column instead of just a static A$16.
    =OFFSET(A$2,COUNTA(A$2:A$15000)-LOOKUP(1E+100,FREQUENCY(IF(INDEX(B$2:H$15000,0,ROWS(M$3:M5))=L5,ROW(A$2:A$16)),IF(INDEX(B$2:H$15000,0,ROWS(M$3:M5))<>L5,ROW(A$2:A$16)))),0)

  21. #21
    Registered User
    Join Date
    12-17-2015
    Location
    London, England
    MS-Off Ver
    2010
    Posts
    27

    Re: Find the address of the last Unique Cell in an array

    I have attached an example file (same as before but illustrating the above).
    Any help much appreciated as always. I have been playing around with the formula for a week and have yet to crack it!
    To refresh your memories I am trying to find the date of the last non-blank, non-repeat cell for each column.
    Attached Files Attached Files

  22. #22
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Find the address of the last Unique Cell in an array

    My head hurts just thinking about this!

    Let me see if I can come up with something. No guarantees!

  23. #23
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Find the address of the last Unique Cell in an array

    Ok, this seems to work.

    Here's the file...
    Attached Files Attached Files

+ 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. Find Unique Values - Need Not Array Formula
    By Neyme in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-30-2016, 04:36 PM
  2. Urgent, please help, code modification, find next, find, vba
    By rojoseph in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-25-2015, 06:02 AM
  3. formula to generate the address of a cell which holds a unique value in workbook
    By MichaelPhilipsz in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-14-2014, 01:22 AM
  4. Need an array formula to find unique records, but don't know how to do it
    By alchavar in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-22-2013, 02:43 PM
  5. Find a cell address containing a value within an array
    By JeffRW in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 10-06-2013, 11:42 AM
  6. Replies: 7
    Last Post: 10-06-2013, 11:42 AM
  7. Replies: 3
    Last Post: 08-13-2012, 11:44 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