I have created the code below that compare two spreadsheets . It initially compares the range of value from sheet1 ("Status") to sheet2 ("Interface") . Whenever a range matches with the ranges present in other sheet , it does nothing .When the range does not any matches in the other sheet , then the entire record is copied from sheet2 to sheet1 . I have around 1500 rows of data in both sheets with 15 columns . It takes around 30 minutes . . I look forward to see If I could get any help.
Option Explicit
Function UpdateNEW() As Long
' This Sub will do the Following Update
' Run through all records in NEW
' if found in Steps ---> Do nothing
' if not found in Steps ----> Add it to Steps
'
Dim WSO As Worksheet
Dim WSN As Worksheet
Dim MaxRowO As Long, MaxRowN As Long, I As Long, J As Long, lAdd As Long
Dim sJob As String, sOps As String, sFirstAddress As String
Dim cCell As Range
Dim bNotFound As Boolean
'---> Disable Events
With Application
.EnableEvents = False
.DisplayAlerts = False
.ScreenUpdating = False
End With
'---> Set Variables
Set WSO = Sheets("Steps")
Set WSN = Sheets("Interface")
MaxRowO = WSO.Range("A" & WSO.Rows.Count).End(xlUp).Row
MaxRowN = WSN.Range("C" & WSN.Rows.Count).End(xlUp).Row
WSN.Range("P6:P" & MaxRowN).ClearContents
'---> Loop thruough all rows in sheet New
For I = 6 To MaxRowN
bNotFound = False
sJob = WSN.Cells(I, "D")
sOps = WSN.Cells(I, "E")
Set cCell = WSO.Range("B2:B" & MaxRowO).Find(what:=sJob, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)
If Not cCell Is Nothing Then
bNotFound = True
sFirstAddress = cCell.Address
Do
'---> Check to See if Ops if found for that Job
If WSO.Cells(cCell.Row, "C") = sOps Then
bNotFound = False
Exit Do
End If
Set cCell = WSO.Range("B2:C" & MaxRowO).FindNext(cCell)
Loop While Not cCell Is Nothing And cCell.Address <> sFirstAddress
Else
bNotFound = True
End If
'---> Add Record to OLD if Not Found
If bNotFound Then
WSN.Range("C" & I & ":O" & I).Copy WSO.Range("A" & MaxRowO + 1)
'WSN.Range("P" & I) = "Copied to OLD"
'WSO.Range("N" & MaxRowO + 1) = sJob & " " & sOps & " Copied from New row " & I
MaxRowO = MaxRowO + 1
lAdd = lAdd + 1
End If
Next I
'---> Enable Events
With Application
.EnableEvents = True
.DisplayAlerts = True
.ScreenUpdating = True
End With
UpdateNEW = lAdd
End Function