Consulting

Results 1 to 4 of 4

Thread: vba Help - extract Matching value

  1. #1
    Banned VBAX Contributor
    Joined
    Aug 2017
    Posts
    144
    Location

    vba Help - extract Matching value

    Hi Team,

    I have attached input file , I am looking excel formula or code in vba/both.

    In Input sheets Column A is player Name,
    Column B - Country Name
    Column C - Captain Name


    I want to fill Column C, captain Name by checking in Master Template.
    Expected result is in Column J of Input sheets.


    Thanks in advance for your help.




    Regards,
    mg
    Attached Files Attached Files

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Capture.JPG

    The VLookup() is pretty basic

    In C2 and copy down

    =VLOOKUP(A2,'Master Template'!$A:$C,3,FALSE)
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    Banned VBAX Contributor
    Joined
    Aug 2017
    Posts
    144
    Location
    Hi Paul,

    Thanks for your help, Actually my data is little different,
    my lookup value should be always a2&b2 concatenation and so on ....
    =VLOOKUP(A2&B2,'Master Template'!CD,2,0) I get result with this, if I merge column A and B in C Column Master Template sheets.

    with helper column in Master Template I get the result.

    is it possible to get result without helper column.


    Regards,
    mg

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Maybe you need to update your attachment

    The is no data in Col D in Master Template, and there is no helper column built from other columns (using formulas)

    Col A on Input is used to look for a equal in Col A on template

    Are you saying that you want to match NAME+COUNTRY and get CAPTAIN?????????????????


    Option Explicit
    
    
    Function VLookup2(Input1 As Variant, Input2 As Variant, DataLookup As Range, DataReturn As Range) As Variant
        Dim i As Long, rowLast As Long
        Dim i1 As Variant, i2 As Variant
        
        VLookup2 = CVErr(xlErrNA)
        On Error GoTo NiceExit
        
        With DataReturn
            rowLast = .Parent.Cells(.Rows.Count, .Column).End(xlUp).Row
        End With
        
        i1 = LCase(Input1)
        i2 = LCase(Input2)
        
        For i = 1 To rowLast
            If i1 = LCase(DataLookup.Cells(i, 1).Value) And i2 = LCase(DataLookup.Cells(i, 2).Value) Then
                VLookup2 = DataReturn.Cells(i, 1).Value
                Exit Function
            End If
        Next i
    
    
        Exit Function
    
    
    NiceExit:
    
    
    End Function
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •