Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to compare 2 columns and output the non matches??

Status
Not open for further replies.

paulk29

Technical User
Jul 15, 2003
113
Hi,
I have two lists of IP addresses, I want to compare list A to list B and output what does not match from list B into another Column. Does anyone know how to do this?
I have a macro that will output the matches in both Lists below;
Thanks
Paul

Sub Find_Matches()
Dim CompareRange As Variant, x As Variant, y As Variant
' Set CompareRange equal to the range to which you will
' compare the selection.
Set CompareRange = Range("C1:C5")
' NOTE: If the compare range is located on another workbook
' or worksheet, use the following syntax.
' Set CompareRange = Workbooks("Book2"). _
' Worksheets("Sheet2").Range("C1:C5")
'
' Loop through each cell in the selection and compare it to
' each cell in CompareRange.
For Each x In Selection
For Each y In CompareRange
If x = y Then x.Offset(0, 1) = x
Next y
Next x
End Sub


Paul Kilcoyne B eng. CCNA
 
Have you tried the Access "Find Unmatched" query wizard?

Sam_F
"90% of the problem is asking the right question.
 
Sam,
can you explain what you mean by the Access find unmatched query wizard?? I'm only new to VB...be gentle
Thanks
Paul

Paul Kilcoyne B eng. CCNA
 
paulk29,

I think I see your confusion (or mine). This is an Access forum. Correct me if I am wrong, but I believe you are trying to run this macro in Excel??

If Excel then try this...


If not then try using SQL (make table query)

How about this. (I am assumming table names)...

Code:
SELECT * FROM listA WHERE yourfieldname NOT IN (select yourfieldname from listB )

I hope this helps...
 
Yeah, what he said... ;-B

Sam_F
"90% of the problem is asking the right question.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top