PDA

View Full Version : Solved: Comparing two columns of data and outputting the differences



flea333
04-02-2010, 11:33 AM
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!!

parttime_guy
04-02-2010, 08:14 PM
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!!!:hi:

mdmackillop
04-03-2010, 06:25 AM
Hi Flea,
Welcome to VBAX


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

flea333
04-20-2010, 06:16 PM
Thanks bro. That will help.