This macro will do it. Put the macro into the Master workbook and save as a macro-enabled workbook. The macro will prompt you to pick the Update file from your hard drive, it will open it and run the update.
If all invoices are found, it will tell you so and close the Update workbook.
If all invoices are not found, it will highlight the ones it did not find and leave the workbook open for review.
Option Explicit
Sub UpdatePayments()
Dim ws1 As Worksheet
Dim wbName As String
Dim wb2 As Workbook
Dim ws2 As Worksheet
Dim InvRNG As Range
Dim Invoice As Range
Dim InvFND As Range
Dim BadCnt As Long
wbName = Application.GetOpenFilename("Microsoft Office Excel Files (.xlsx),.xlsx")
If wbName = "False" Then Exit Sub
Application.ScreenUpdating = False
Set ws1 = ThisWorkbook.Sheets("Sheet1")
Set wb2 = Workbooks.Open(wbName)
Set ws2 = wb2.Sheets("Sheet1")
Set InvRNG = ws2.Range("C:C").SpecialCells(xlConstants, xlNumbers)
On Error Resume Next
For Each Invoice In InvRNG
Set InvFND = ws1.Range("J:J").Find(Invoice, LookIn:=xlValues, LookAt:=xlWhole)
If Not InvFND Is Nothing Then
ws1.Range("N" & InvFND.Row).Resize(, 2).Value = Invoice.Offset(, 1).Resize(, 2).Value
Set InvFND = Nothing
Else
Invoice.Interior.ColorIndex = 3
BadCnt = BadCnt + 1
End If
Next Invoice
If BadCnt > 0 Then
MsgBox "There were " & BadCnt & " invoices not found. They have been highlighted for reference."
wb2.Activate
ws2.Activate
Else
MsgBox "All invoices were found and updated."
wb2.Close False
End If
Application.ScreenUpdating = True
End Sub
Bookmarks