Consulting

Results 1 to 3 of 3

Thread: Solved: match and return offset value in cell

  1. #1
    VBAX Mentor
    Joined
    Sep 2004
    Posts
    431
    Location

    Solved: match and return offset value in cell

    What I need is a code ( or most likely a formula) that will match [A2:B2] to columns M:N and return the offset value in column O in D2
    In my example the value in cell D2 should be HIT
    Thank you
    Last edited by ndendrinos; 09-03-2009 at 09:40 AM.
    Thank you for your help

  2. #2
    VBAX Tutor nst1107's Avatar
    Joined
    Nov 2008
    Location
    Monticello
    Posts
    245
    Location
    I have no doubt there is a way to do this without a UDF, but here is a solution for you. Copy and paste the following code into your Module2, and type "=MATCHBOTH(A2:B2,M3:N21)" into D2.[vba]Option Explicit
    Function MATCHBOTH(WhatToLookFor As Range, WhereToLook As Range) As String
    Dim c As Range
    Dim firstAddress As String
    Set c = WhereToLook.Columns(1).Find(WhatToLookFor.Columns(1))
    firstAddress = c.Address
    Do
    If c.Offset(, 1) <> WhatToLookFor.Columns(2) Then
    Set c = WhereToLook.Columns(1).FindNext
    Else
    MATCHBOTH = c.Offset(, 2): Exit Do
    End If
    Loop Until c.Address = firstAddress
    End Function
    [/vba]

  3. #3
    VBAX Mentor
    Joined
    Sep 2004
    Posts
    431
    Location
    Thank you nst1107 just what's needed
    Thank you for your help

Posting Permissions

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