+ Reply to Thread
Results 1 to 3 of 3

Match Values Based on First Column then Between Values in Next Two Columns

Hybrid View

  1. #1
    Registered User
    Join Date
    09-24-2014
    Location
    FL, USA
    MS-Off Ver
    Office 2010
    Posts
    18

    Match Values Based on First Column then Between Values in Next Two Columns

    Hi,

    I am trying to find values based on the following criteria and need help with formula or script:
    For each value in column A on Sheet1 find the matching value in Column A on Sheet2.
    Then find row where value in column B on Sheet1 is between values in Columns B and C on Sheet2.
    Where there is a match fill in the value from Column D on Sheet2 in Column C of Sheet1.

    Attached is a sample file with the first 3 cases filled in manually. Actually sheet has over 500 records, so I can't do this manually. Any help is appreciated.
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Match Values Based on First Column then Between Values in Next Two Columns

    VBA
    Sub test()
        Dim a, e, i As Long, ii As Long, w, temp, dic As Object
        Set dic = CreateObject("Scripting.Dictionary")
        a = Sheets("sheet2").Cells(1).CurrentRegion.Value
        For i = 3 To UBound(a, 1)
            If Not dic.exists(a(i, 1)) Then
                ReDim w(1 To 3, 1 To 1)
            Else
                w = dic(a(i, 1))
                ReDim Preserve w(1 To 3, 1 To UBound(w, 2) + 1)
            End If
            For ii = 2 To 4
                w(ii - 1, UBound(w, 2)) = a(i, ii)
            Next
            dic(a(i, 1)) = w
        Next
        With Sheets("sheet1").Cells(1).CurrentRegion.Offset(1)
            a = .Value
            For i = 1 To UBound(a, 1) - 1
                temp = a(i, 1): a(i, 1) = Empty
                If dic.exists(temp) Then
                    For ii = 1 To UBound(dic(temp), 2)
                        If (a(i, 2) >= dic(temp)(1, ii)) * (a(i, 2) <= dic(temp)(2, ii)) Then
                            a(i, 1) = dic(temp)(3, ii): Exit For
                        End If
                    Next
                End If
            Next
            .Columns(3).Value = a
        End With
    End Sub

  3. #3
    Registered User
    Join Date
    09-24-2014
    Location
    FL, USA
    MS-Off Ver
    Office 2010
    Posts
    18

    Re: Match Values Based on First Column then Between Values in Next Two Columns

    Thank you! Works great!

+ 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. Match values from two columns having similar values in 1st column if not error
    By csunilkumar in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-23-2014, 08:32 AM
  2. Count Unique values in Column based on values in other columns
    By dmschave in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-17-2014, 11:06 AM
  3. Replies: 1
    Last Post: 11-16-2013, 05:18 AM
  4. [SOLVED] Distribute values in columns based on match between two other columns
    By hydrgal in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-15-2013, 04:07 AM
  5. [SOLVED] Sum values in column based on variable values in 3 other columns
    By Winon in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-03-2012, 10:13 AM
  6. SUMIF - add values from one column based on values in two other columns
    By goodmike in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-30-2008, 08:04 PM
  7. Get values in a column based on values in two other columns
    By ssb in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-30-2006, 11:00 PM

Tags for this Thread

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