+ Reply to Thread
Results 1 to 3 of 3

Trying to campare two columns with another 2 columns

Hybrid View

  1. #1
    Registered User
    Join Date
    09-30-2013
    Location
    Nelson Bay, Australia
    MS-Off Ver
    Excel 2003
    Posts
    28

    Trying to campare two columns with another 2 columns

    Good morning everyone,

    Hopefully someone can help me out.

    I'm tryin to go through each pair of cells for each row in column A and B, and see if they match another pair of cells elsewhere.

    Here's an example worksheet.
    example.xlsx

    So I want a VBA code that basically does the following:

    If Range("A1:B1") <<(appears in lookup table)>> then
    I will loop this to repeat on every row.

    So in the example, rows 7 to 10 would enter the IF statement, the rest would not.

    If I concantenate A and B and the concantenate the table, I can just about do it with match, but I'd like to see if I can avoid adding more columns.

    Any help that can be provided is appreciated.

    VonRobbo

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,995

    Re: Trying to campare two columns with another 2 columns

    I tested this code on your sample file:
    Private Sub FindDoubleMatches()
    
       Dim LookupTable As Range
       Dim R As Long ' row number
       Set LookupTable = Range("I5:J9")
       
       R = 1
       Do While Cells(R, "A") <> ""
          If PairIsFound(LookupTable, Cells(R, "A"), Cells(R, "B")) Then
             MsgBox "Row " & R & " found in lookup table "
          End If
          R = R + 1
       Loop
       
    End Sub
    
    Private Function PairIsFound(LookupTable As Range, Element1 As Variant, Element2 As Variant) As Boolean
    
       Dim R As Long
       
       PairIsFound = False
       
       Do While LookupTable.Cells(R, 1) <> ""
       
          If Element1 = LookupTable.Cells(R, 1) And Element2 = LookupTable.Cells(R, 2) Then
             PairIsFound = True
             Exit Do
          End If
          
          R = R + 1
          
       Loop
       
    End Function
    I suspect this can also be done with formulas without adding extra columns, not 100% sure. What is it you want to do when you find a match?
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    09-30-2013
    Location
    Nelson Bay, Australia
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: Trying to campare two columns with another 2 columns

    If there is a match, I just want to change the colour of the row where the match exists, to highlight it.

    That's something I'll be able to do simply by replacing the message box line. Thanks heaps for your help.

+ 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. [SOLVED] Macros to transpose from multiple columns to selected columns and maintaining cell format
    By rrajnish in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-09-2013, 01:45 PM
  2. Combining multiple rows from 2 columns into sorted columns depending on 1st columns value
    By Dexamphetamine in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-11-2013, 10:00 AM
  3. MAcro to - copy, transpose, text to columns, remove column A, combine all columns in 1
    By galvinpaddy in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 02-07-2013, 08:48 AM
  4. Replies: 6
    Last Post: 12-26-2012, 01:43 PM
  5. columns in excel to reflect array of values entered in previous two columns
    By netvasi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-19-2011, 01:12 AM

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