+ Reply to Thread
Results 1 to 7 of 7

Return values of duplicates

  1. #1
    Registered User
    Join Date
    09-19-2014
    Location
    toronto, canada
    MS-Off Ver
    2010
    Posts
    4

    Return values of duplicates

    Hi

    I'm running a Vloopkup on a table, problem with Vlookups is that they pickup the first matching lookup value but ignores any others that match in the same column:

    ah 234
    sa 334
    po 434
    ah 534
    ra 634
    sur 734
    ah 834

    I want to list all the values for ah in ONE cell, ie. 234,534,834. Any advice on how to do this? I'm thinking I need to put this into an array but not sure how.

    The formula I'm actually using is

    =IF(ISNA(VLOOKUP($A569,Payments,8,FALSE)),"",(VLOOKUP($A569,Payments,8,FALSE)))

    thanks!

  2. #2
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Return values of duplicates

    Hi kneenah,
    Welcome to the Forum.

    Assuming your data is in the range A1:A14 and D1 = ah, then try this Array Formula. Remember Array Formula requires special keystrokes Ctrl+Shift+Enter instead of just Enter which you normally use in case of a regular excel formula. i.e. after typing the array formula in the formula cell, don't press Enter, instead hold down the Ctrl+Shift together and then hit Enter. When an array formula is entered correctly, you will notice in the formula bar that the formula gets surrounded by the Curly Brackets { } and if you don't see the curly brackets in the formula bar, select the formula cell, press F2 (function key) and hold down the Ctrl+Shift together and hit Enter again to correctly enter the formula as an Array Formula.

    In E1
    Please Login or Register  to view this content.
    and then copy down until you get blank cells.

    For detail see the attached sheet.
    Attached Files Attached Files
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

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

    Re: Return values of duplicates

    Quote Originally Posted by kneenah View Post

    I want to list all the values for ah in ONE cell, ie. 234,534,834.
    You'll need a VBA function to do it.

    With your file open...

    Press the key combination of Alt+F11 to open the Visual Basic Editor

    Goto the menu Insert>Module

    Copy the VBA code here and paste it into the window that opens on the right side of the screen.

    Press the key combination of ALT+Q to close the Visual Basic Editor and return to Excel.

    Then....

    Data Range
    A
    B
    C
    D
    E
    1
    ------
    ------
    ------
    ------
    ------
    2
    ah
    234
    ah
    234,534,834
    3
    sa
    334
    4
    po
    434
    5
    ah
    534
    6
    ra
    634
    7
    sur
    734
    8
    ah
    834


    Enter this array formula** in E2:

    =concatall(IF(A2:A8=D2,B2:B8,""),",")

    ** 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.

    You'll have to save the file as a macro enabled file in the *.xlsm format.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  4. #4
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Thumbs up Re: Return values of duplicates

    Try this..
    Using Helper columns..
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Check the attached file..
    Attached Files Attached Files
    Regards,
    Vikas Gautam
    Excel-buzz.blogspot.com

    Excel is not a matter of Experience, its a matter of Application.

    Say Thanks, Click * Add Reputation

  5. #5
    Registered User
    Join Date
    09-19-2014
    Location
    toronto, canada
    MS-Off Ver
    2010
    Posts
    4

    Re: Return values of duplicates

    Thanks everyone for the help!

    Tony - trying your code :

    Dim DataIndex As Variant 'Used to loop through arrays, range objects, and collections
    Dim strResult As String 'Used to build the result string

    'Test if varData is an Array, Range, or Collection
    If IsArray(varData) _
    Or TypeOf varData Is Range _
    Or TypeOf varData Is Collection Then

    'Found to be an, array, range object, or collection
    'Loop through each item in varData
    For Each DataIndex In varData
    'Check if the item isn't empty
    If Len(DataIndex) > 0 Then
    'Found the item isn't empty, check if user specified bUnique as True
    If bUnique = True Then
    'bUnique is true, check if the item has been included in the result yet
    If InStr(1, "||" & strResult & "||", "||" & DataIndex & "||", vbTextCompare) = 0 Then
    'Item has not been included in the result, add item to the result
    strResult = strResult & "||" & DataIndex
    End If
    Else
    'bUnique is not true, add item to the result
    strResult = strResult & "||" & DataIndex
    End If
    End If
    Next DataIndex

    'Correct strResult to remove beginning delimiter and convert "||" to the specified sDelimiter
    strResult = Replace(Mid(strResult, 3), "||", sDelimiter)

    Else
    'Found not to be an array, range object, or collection
    'Simply set the result = varData
    strResult = varData
    End If

    'Output result
    ConcatAll = strResult

    End Function


    and I'm getting a Name error in my worksheet, and this error in my VBA - Compile error: Invalid outside procedure

    Any ideas what's wrong?

  6. #6
    Registered User
    Join Date
    09-19-2014
    Location
    toronto, canada
    MS-Off Ver
    2010
    Posts
    4

    Re: Return values of duplicates

    It works! thanks! I see that I was missing the first few lines of code :/

  7. #7
    Registered User
    Join Date
    09-19-2014
    Location
    toronto, canada
    MS-Off Ver
    2010
    Posts
    4

    Re: Return values of duplicates

    I'm trying to apply this concept to the actual formula I'm using (in my original post so don't think this is a new thread):


    =IF(ISNA(VLOOKUP($A569,Payments,8,FALSE)),"",(VLOOKUP($A569,Payments,8,FALSE)))

    using your concatall formula I have:

    =ConcatAll(IF(ISNA(VLOOKUP($A586,Payments,6,FALSE)),"",(VLOOKUP($A586,Payments,6,FALSE))),",")

    The array doesn't work; only returns the first value. Any ideas what I'm doing wrong? Thanks!!!!

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

    Re: Return values of duplicates

    VLOOKUP will only return a single result in that application.

    You have to use it in the form that I showed in post #3.

+ 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. Replies: 1
    Last Post: 07-30-2014, 02:37 PM
  2. [SOLVED] Macro to find duplicates, concatenate Unique Values, then delete old duplicates
    By lesoies in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-17-2013, 04:32 PM
  3. return multiple values horizontally while removing duplicates
    By kingi in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-24-2013, 03:55 PM
  4. Replies: 6
    Last Post: 03-29-2012, 12:16 AM
  5. Excel 2007 : return TXT Values and remove duplicates?
    By fordzilla in forum Excel General
    Replies: 0
    Last Post: 09-29-2011, 06:20 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