Thread: Comparing lists
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
kkknie[_104_] kkknie[_104_] is offline
external usenet poster
 
Posts: 1
Default Comparing lists

Here's some code based on your original:

Code
-------------------
Private Sub CmdRec_Click()

Dim i As Long
Dim j As Long
Dim bFound As Boolean

'Finds everything in column A that is not in column B
ListOld.Clear
Sheets("Sheet3").Select
Range("A4").Select

For i = 4 To Range("B65536").End(xlUp).Row
bFound = False
For j = 4 To Range("A65536").End(xlUp).Row
If Range("A" & i).Value = Range("B" & j).Value Then
bFound = True
Exit For
End If
Next
If bFound = False Then ListOld.AddItem Range("A" & i).Value
Next

'Finds everything in column B that is not in column A
ListNew.Clear
Sheets("Sheet3").Select
Range("A4").Select

For i = 4 To Range("B65536").End(xlUp).Row
bFound = False
For j = 4 To Range("A65536").End(xlUp).Row
If Range("A" & j).Value = Range("B" & i).Value Then
bFound = True
Exit For
End If
Next
If bFound = False Then ListNew.AddItem Range("B" & i).Value
Next


End Su
-------------------

I assumed both A and B ranges started in row 4 (thus the for i = 4 t
...). If this is wrong, change the 4 to wherever your data starts.



--
Message posted from http://www.ExcelForum.com