Consulting

Results 1 to 4 of 4

Thread: Solved: Comparing two columns of data and outputting the differences

  1. #1
    VBAX Regular
    Joined
    Oct 2007
    Posts
    34
    Location

    Solved: Comparing two columns of data and outputting the differences

    I am looking for the most efficient VBA function to do the following:

    1) Worksheet1: Using a user specified column of cells (say B2:B10) on the same worksheet as the button to initiate the macro - Source Worksheet,
    2) Worksheet2: Find each value from the list on the Source worksheet in another worksheets column of data cells (starting on a predefined cell, up to where there are blanks in a specified column on another sheet).
    3) Worksheet3: Write any values not found on a third worksheet that is specified. Check for worksheet/create if not there.

    For step 1 I would also be happy if you could specify a gap within the data, so B2:B10; B13:B20. etc.

    An example of the computation and data is below:

    Worksheet1:

    B2:B10;B13:B20 = A,B,C,D,..K

    Worksheet2:

    Range D12:...until blank = A,A,A,A,A,A,A,A,A,A,A,A,A,A,B,B,B,B,B,B,B,B,C,......K,K,K,K,K,K....X,X,X,X, X,Y,Y,Y,
    Z,Z,Z,Z,blank,blank....

    Worksheet3:

    Output the following starting at a predefined row/col:
    Source:
    D
    Dest:
    X,
    Y,
    Z

    Since D is not found in Worksheet2 it is shown. X,Y,Z is not in the list from Worksheet1 and so they are displayed.
    An alternative feature I'd like to employee for the Source data in Worksheet1 is to highlight the text/fill with a color when it is not found in Worksheet2 but still print out the mismatch values from Worksheet2 on Worksheet3 as above.


    Thanks!!

  2. #2
    Hi Flea,

    Try out this tool - It's Free

    http://xldynamic.com/source/xld.DupMaster.html

    Hope it helps u.

    Also check out this link

    http://www.vbaexpress.com/cooltools.php

    Very Informative...

    Best regards - Happy Exceling!!!

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Flea,
    Welcome to VBAX

    [vba]
    Option Explicit

    Sub DoSearch()
    Dim Source As Range
    Dim Data As Range
    Dim Tgt As Range
    Dim cel As Range
    Dim c As Range
    Dim i As Long

    With Sheets(1)
    Set Source = Range(.Cells(2, 2), .Cells(Rows.Count, 2).End(xlUp))
    End With

    Set Data = Sheets(2).Columns(2)
    Sheets.Add after:=Sheets(Sheets.Count)
    ActiveSheet.Name = "Result"
    Set Tgt = ActiveSheet.Cells(2, 2)

    For Each cel In Source
    If cel <> "" Then
    Set c = Data.Find(cel)
    If c Is Nothing Then
    Tgt.Offset(i) = cel
    i = i + 1
    End If
    End If
    Next
    End Sub

    [/vba]
    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'

  4. #4
    VBAX Regular
    Joined
    Oct 2007
    Posts
    34
    Location
    Thanks bro. That will 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
  •