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


'assume list 1 in col a, starting in row 2 with list 2 in col b an
output in col c
'I have not tested this code - it is adapted from code that work
though
'
Option Explicit
Sub Compare()
'
Dim baditem(1000)
Dim list1 As range
Dim list2 As Range
'
' Clear old Results
'
Range("c2:c1000").ClearContents
set list1 = range(cells(2 , 1).cells(2 , 1).end(xldown))
set list2 = range(cells(2 , 2).cells(2, 2).end(xldown))
list1end = range("list1").end(xldown).row
'
' Search on list 2 for items on list 1
'
i = 0
For j = 2 list1end
thisitem = Cells(j, 1).value
Set rng = Range("list2").Find(thisitem)
If rng Is Nothing Then GoTo baditem
goto nextj
baditem:
i = i + 1
baditem(i) = thisitem
nextj:
Next j
baditems = i
For m = 1 To baditem
Cells(m+1, 3).Value = baditem(m)
Next m
End Su

--
duan

-----------------------------------------------------------------------
duane's Profile: http://www.excelforum.com/member.php...fo&userid=1162
View this thread: http://www.excelforum.com/showthread.php?threadid=26966