Hi,
have the code below but when executed the values are put at the bottom starting at cell "A71" how can make to start at the top starting on cell "A2".
here is the code:
thank you
have the code below but when executed the values are put at the bottom starting at cell "A71" how can make to start at the top starting on cell "A2".
here is the code:
VBA Code:
Sub FIND_DIFFERENCES()
Dim sh1 As Worksheet, sh2 As Worksheet, sh3 As Worksheet
Dim C As Range, f As Range, mydiffs As Long
Dim r1 As Range, r2 As Range, lr As Long
Set sh1 = Sheets("NCL_INVOICES")
Set sh2 = Sheets("VENDOR_INVOICES")
Set sh3 = Sheets("DIFFERENCES")
Set r1 = sh1.Range("A2", sh1.Range("A" & Rows.Count).End(xlUp))
Set r2 = sh2.Range("A2", sh2.Range("A" & Rows.Count).End(xlUp))
r1.Interior.Color = vbWhite
r2.Interior.Color = vbWhite
For Each C In r1
Set f = r2.Find(C, , xlValues, xlWhole)
If f Is Nothing Then
C.Interior.Color = vbRed
mydiffs = mydiffs + 1
lr = sh3.Range("A" & Rows.Count).End(xlUp).Row + 1
sh3.Range("A" & lr).Resize(1, 6).Value = C.Resize(1, 6).Value
sh3.Range("A" & lr).Offset(, 6).Value = sh1.Name
End If
Next
For Each C In r2
Set f = r1.Find(C, , xlValues, xlWhole)
If f Is Nothing Then
C.Interior.Color = vbRed
mydiffs = mydiffs + 1
lr = sh3.Range("A" & Rows.Count).End(xlUp).Row + 1
sh3.Range("A" & lr).Resize(1, 6).Value = C.Resize(1, 6).Value
sh3.Range("A" & lr).Offset(, 6).Value = sh2.Name
End If
Next
MsgBox mydiffs & " differences found"
End Sub
thank you