+ Reply to Thread
Results 1 to 13 of 13

array dynamic vlookup

Hybrid View

  1. #1
    Registered User
    Join Date
    08-09-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2007
    Posts
    8

    array dynamic vlookup

    Good day,

    I am new here.

    I was searching the forums on how to change:

    date name
    8/9/2011 Mike
    8/9/2011 Mike
    8/10/2011 Lorraine
    8/10/2011 Lorrraine
    8/10/2011 Mike

    to this:
    date name
    8/9/2011 Mike
    8/10/2011 Lorraine
    8/10/2011 Mike

    in a sense, making both the date and name column to be unique.

    I found an answer here but it is not showing unique rows based of per date.

    Please help.

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: array dynamic vlookup

    If your date in column A and the name is in column B, both starting at row 2 then you could put this formula in C2 and copy down the sheet.

    =IF(ISNA(MATCH(B2,$B$1:B1,0)),"",IF(A2<>OFFSET($A$1,MATCH(B2,$B$1:B1,0),0),"","Duplicate"))

    Then you will just have to filter the rows that say "Duplicate" in column C and delete them.

    Edited to add: Poo, I've just realised that while that works fine for the example data you gave, it won't work on a larger data set.
    Last edited by Andrew-R; 08-09-2011 at 04:41 AM.

  3. #3
    Registered User
    Join Date
    08-09-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: array dynamic vlookup

    Thank you Andrew-R!

    This helps a lot. But as I was searching I found this.

    http://www.excelforum.com/excel-work...from-list.html

    I think this is the exact one I'm looking for.

    Mike

  4. #4
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: array dynamic vlookup

    Hi and welcome to the forum.

    You're using XL 2007 so if you select the range and then click on the remove duplicates button on the ribbon, it will remove the duplicates for you.

    If you were using an earlier version of XL then you could do this using the Advanced Filter instead.
    Hope that helps,

    Colin

    RAD Excel Blog

  5. #5
    Registered User
    Join Date
    08-09-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: array dynamic vlookup

    Hmm, based of the array formula, it only shows unique values from column 1. Nope. still can't get it. Any help? I have tried also naming the 2 columns as ranges as
    column 1 = AFIELD
    column 2 = BFIELD
    I tried the cell C1 for the user to input the date and have names returned for that specific date starting in C2
    and used this array formula:
    {=INDEX(BFIELD,SMALL(IF(BFIELD=$C$1,ROW(BFIELD)-ROW(B2)+1),ROWS($C$2:C2)))}
    which i originally looked up here but it is returning duplicates for that date.
    any suggestions on this?

    Thanks in advance

  6. #6
    Registered User
    Join Date
    08-09-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: array dynamic vlookup

    Thanks Colin!

    What I would like to do is to have a dynamic unique name list based off of a single date on column 1.

    Regards,

  7. #7
    Registered User
    Join Date
    08-09-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: array dynamic vlookup

    {=INDEX(BFIELD,SMALL(IF(BFIELD=$C$1,ROW(BFIELD)-ROW(B2)+1),ROWS($C$2:C2)))}
    should be
    {=INDEX(BFIELD,SMALL(IF(AFIELD=$C$1,ROW(BFIELD)-ROW(B2)+1),ROWS($C$2:C2)))}
    im sorry did not saw that AFIELD.
    anyway this formula returns values for a date which is not unique

  8. #8
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: array dynamic vlookup

    Hi,

    So you want both lists in your workbook? Formulae are not an efficient way to do this.

    See the attached example which automates the advanced filter.
    You can test it by adding to or removing dates/names from columns A and B; it will automatically update the distinct list in columns F and G.

    Option Explicit
    
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        
        Dim rngList As Range
        Dim rngCopyTo As Range
        
        On Error GoTo ErrorHandler
        
        Set rngList = Range("rList")
        
        If Not Intersect(rngList, Target) Is Nothing Then
            
            Set rngCopyTo = Range("rCopyTo")
            
            Application.EnableEvents = False
            rngList.AdvancedFilter action:=xlFilterCopy, copytoRange:=rngCopyTo, Unique:=True
            
        End If
    
    
    ErrorExit:
    
        On Error Resume Next
        
        Application.EnableEvents = True
        
        Exit Sub
        
    ErrorHandler:
    
        MsgBox "Error: " & CStr(Err.Number) & vbNewLine & "Error Description: " & Err.Description
        Resume ErrorExit
        
    End Sub
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    08-09-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: array dynamic vlookup

    wow.....

    i definitely make use of my time with codes. this sure helped me a lot more than you can imagine. Now I can definitely move on with my personal tool that I am developing.

    thanks Colin!

  10. #10
    Registered User
    Join Date
    08-09-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: array dynamic vlookup

    uhm i am thinking of adding an option of let's say i just want the filtered data for a certain date, can we do that based off of the code?

    If Not Intersect(rngList, Target)

    an additional code must be added here before execution of code right?

    Will there be another named range for the date column?

  11. #11
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: array dynamic vlookup

    Hi,
    thinking of adding an option of let's say i just want the filtered data for a certain date, can we do that based off of the code?
    To do that, you need to add a criteria range onto the worksheet and then include it in the Range.AdvancedFilter method. See attached.

    Option Explicit
    
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        
        Dim rngList As Range
        Dim rngCriteria As Range
        Dim rngCopyTo As Range
        
        On Error GoTo ErrorHandler
        
        Set rngList = Range("rList")
        Set rngCriteria = Range("rCriteria")
        
        If Not Intersect(Union(rngList, rngCriteria), Target) Is Nothing Then
            
            Set rngCopyTo = Range("rCopyTo")
            
            Application.EnableEvents = False
            rngList.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=rngCriteria, CopyToRange:=rngCopyTo, Unique:=True
            
        End If
    
    
    ErrorExit:
    
        On Error Resume Next
        
        Application.EnableEvents = True
        
        Exit Sub
        
    ErrorHandler:
    
        MsgBox "Error: " & CStr(Err.Number) & vbNewLine & "Error Description: " & Err.Description
        Resume ErrorExit
        
    End Sub
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    08-09-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: array dynamic vlookup

    Oh so that is how to make it on 2 conditions.

    Thanks again for this.

    Maybe I definitely need to learn codes from now on.

  13. #13
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: array dynamic vlookup

    You're welcome.

    If you are happy with the solution(s) provided, please mark your thread as solved.

+ 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