Consulting

Results 1 to 3 of 3

Thread: Need Help testing if a cells contents match that of a cell in another column

  1. #1

    Need Help testing if a cells contents match that of a cell in another column

    Hello,

    I am trying to test a column of cells to see if an individual cell's contents match the cell contents of any cell in another column.

    What I have is two list of data, in alpha-numeric format. I want to see what data exist in both lists.

    Thanks in advance,

  2. #2
    VBAX Mentor tstav's Avatar
    Joined
    Feb 2008
    Location
    Athens
    Posts
    350
    Location
    You may start with the following, only to get a first feel of one of several ways of checking if cells match. Suppose the columns to check are E and F.
    [vba]Sub test_MatchCells()
    Dim i As long, cell As Range, rng1 As Range, rng2 As Range
    Set rng1 = Range(Range("E1"), Range("E" & Rows.Count).End(xlUp))
    Set rng2 = Range(Range("F1"), Range("F" & Rows.Count).End(xlUp))
    On Error Resume Next
    For Each cell In rng1
    i = WorksheetFunction.Match(cell.Value, rng2, 0)
    If Err Then
    Err.Clear
    Else
    MsgBox "Found " & cell.Value & " " & "Row:" & i
    End If
    Next
    End Sub
    [/vba]
    He didn't know it was impossible, so he did it. (Jean Cocteau)

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Have you seen this excellent programme?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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