I'm trying to write a script that compares values in one list to values in another. If the value is not found in the comparison list, I would like to copy the whole row from one worksheet to another.
Using Application.VLookup/Application.WorksheetFunction.Vlookup, I'm getting a debug error 13/1004 because no value is found. I'd like to trigger off of that no value found to make the copy.
Function Update()
Dim Master As Worksheet
Dim Slave As Worksheet
Dim lrM As Long
Dim lrS As Long
Dim i As Long, m, MLookup As Range
'Dim j As Long, n, SLookup As Range
Set Master = ThisWorkbook.Worksheets("PR Data Windchill")
Set Slave = ThisWorkbook.Worksheets("PR Data")
Set MLookup = ThisWorkbook.Worksheets("PR Data").Columns(1)
'Set SLookup = ThisWorkbook.Worksheets("PR Data Windchill").Columns(7)
lrM = Master.Cells(Master.Rows.Count, "A").End(xlUp).Row
lrS = Slave.Cells(Slave.Rows.Count, "A").End(xlUp).Row
With Master
For i = 2 To lrM
m = Application.Match(.Rows(i).Cells(1).Value, MLookup, 0)
If IsError(m) Then
.Rows(i).Copy Slave.Cells(Slave.Rows.Count, "A").End(xlUp).Offset(1, 0)
End If
Next i
End With
'With Slave
' For j = 2 To lrS
' n = Application.Match(.Rows(j).Cells(1).Value, SLookup, 0)
' If IsError(n) Then
' .Rows(j).Copy Slave.Cells(Slave.Rows.Count, "A").End(xlUp).Offset(1, 0)
' End If
' Next j
'End With
Application.CutCopyMode = False
MsgBox ("Matrix Update Complete")
End Function