+ Reply to Thread
Results 1 to 5 of 5

compare 2 columns and create new column with missing values in second column

Hybrid View

  1. #1
    Registered User
    Join Date
    08-24-2012
    Location
    Belgium
    MS-Off Ver
    Excel 2003
    Posts
    2

    compare 2 columns and create new column with missing values in second column

    Hello,

    I'm trying to write a macto to search all values from column A of sheet1 in column A of sheet2 and create a new list in sheet3 of all the values from sheet 1 which are not found in sheet2

    thanks in advance

  2. #2
    Forum Contributor
    Join Date
    09-29-2011
    Location
    Kolkata, India
    MS-Off Ver
    Excel 2003/2007
    Posts
    182

    Re: compare 2 columns and create new column with missing values in second column

    Hi Jroelan,

    Welcome in Excel Forum.

    I have prepared a small macro which may help you. I have preapared this in a single sheet. However, you can modify this to show the result in sheet3 keeping data in sheet1 and 2. Hope it will guide you. The same can be done by macro only, but I thought it will help you in future if you try it yourself. Let us know. We certainly help if require.
    Attached Files Attached Files

  3. #3
    Forum Contributor
    Join Date
    09-29-2011
    Location
    Kolkata, India
    MS-Off Ver
    Excel 2003/2007
    Posts
    182

    Re: compare 2 columns and create new column with missing values in second column

    Sorry friend,

    Earlier I have attached file with wrong formula. However, the formula also help to find the duplicate record.
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    08-24-2012
    Location
    Belgium
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: compare 2 columns and create new column with missing values in second column

    Thanks,
    Now I have somthing to start fomm

  5. #5
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: compare 2 columns and create new column with missing values in second column

    Here give this a try

    Sub abc()
     Dim aResults() As Variant
     Dim FoundCell As Range
     Dim Sheet1Range As Range, Sheet2Range As Range, Cell As Range
      
      ReDim aResults(1 To 1)
    ' Adjust for your range on sheet1
      Set Sheet1Range = Worksheets("Sheet1").Range("A2:A5")
      
      For Each Cell In Sheet1Range
    '    Adjust for your range on sheet2
         Set Sheet2Range = Worksheets("Sheet2").Range("A2:A5")
         
         Set FoundCell = Sheet2Range.Find(What:=Cell, LookAt:=xlWhole)
         If FoundCell Is Nothing Then
            aResults(UBound(aResults)) = Cell
            ReDim Preserve aResults(1 To UBound(aResults) + 1)
         End If
         
      Next
      
     Worksheets("Sheet3").Range("a2").Resize(UBound(aResults)) = WorksheetFunction.Transpose(aResults)
    End Sub
    Last edited by mike7952; 08-27-2012 at 12:38 AM.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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