View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Simon Letten Simon Letten is offline
external usenet poster
 
Posts: 20
Default Extract only non-matching data

I think it is easier to use the Find method. This code should do the trick:

Sub Add_New_Entries()

Dim rngMasterData As Range
Dim rngNewData As Range
Dim cell As Range
Dim rngEntryFound As Range

Set rngNewData =
Workbooks("newdata.xls").Worksheets("Sheet2").Rang e("A1:A4") ' <-- change this
Set rngMasterData = ThisWorkbook.Worksheets("Sheet2").Range("C1:C3") '
<-- change this

' loop through all the new data looking for a matching value in master
data
For Each cell In rngNewData
Set rngEntryFound = rngMasterData.Find(What:=cell.Value,
LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=True)
If (rngEntryFound Is Nothing) Then
' The value in cell.Value does not exist in master data
' So add value to Master data
MsgBox "not found"
Else
' Do nothing
End If
Next cell

CleanUp:
If Not (rngEntryFound Is Nothing) Then Set rngEntryFound = Nothing
If Not (rngNewData Is Nothing) Then Set rngNewData = Nothing
If Not (rngMasterData Is Nothing) Then Set rngMasterData = Nothing

End Sub
--
HTH

Simon


"vect98" wrote:


I've read through similar posts and tried their macros but still can't
find a solution.

I have 2 sheets one which is downloaded each time and a master one.
both have a list of items and i want to be able to with a macro search
the newly downloaded list and only update the master list with items
that a new or don't already exist. So just the non-matching ones. i
tried this macro but i onyl get a list of all data and evcen then im
having trouble copying it accross.

Sub Find_Matches()
Dim CompareRange As Variant
Dim x As Variant
Dim y As Variant
Set CompareRange = Worksheets("Sheet1").Range("C2:C120")
Dim dMat As String
For Each x In Selection
For Each y In CompareRange
If x < y Then
dMat = y
ActiveCell = dMat
Else
ActiveCell = "No Item"
End If
Next y
Next x

All i want to do is compare 2 columns of the same type - as in use that
as the unique identifier "item number"

Thanks


--
vect98
------------------------------------------------------------------------
vect98's Profile: http://www.excelforum.com/member.php...o&userid=26365
View this thread: http://www.excelforum.com/showthread...hreadid=396372