あなたが何を必要としているのかを理解していれば、これに対する単純な4行の答えはありません. しかし、それは単純な 90 行の答えです。2 つのシート「Final」と「Orig」の列定義に合わせて Enum を維持する必要があります。また、範囲定義 (シート名など) を変更する必要がある場合があります。VBE Menu/Tools/References を実行し、「Microsoft Scripting Runtime」をチェックしてディクショナリ オブジェクトを取得する必要があります。冗長に思われる場合は申し訳ありませんが、維持しやすいはずです。
Option Explicit
' This is the definition of the columns on "Final" sheet
Enum final_record
fr_partid
fr_descr
fr_vendorid
fr_po
fr_due
fr_quantdue
fr_status
fr_orig
fr_desired
fr_comment
fr_dayslate
fr_pri
fr_shoporder
fr_remarks
fr_end
End Enum
' This is the definition of the columns on "Orig" sheet
Enum orig_record
or_po
or_partid
or_vendorid
or_descr
or_comment
or_status
or_quant
or_balance
or_orig
or_requested
or_end
End Enum
Sub UpdateDescrAndShipDate()
' Update comments and required ship date if matches po/partid/description.
' Else add a new row.
Dim lRows As Long, lRow As Long, rFinal As Range, rOrig As Range, sKey As String
Dim lTarget As Long, lNew As Long
Dim dictTarget As New Scripting.Dictionary
' Get Final rows into dict by key
Set rFinal = Worksheets("Final").Range("A1")
lRows = rFinal.Offset(65000, 0).End(xlUp).Row - rFinal.Row
For lRow = 1 To lRows
sKey = rFinal.Offset(lRow, fr_po).Value & "|" & _
rFinal.Offset(lRow, fr_partid).Value & "|" & _
rFinal.Offset(lRow, fr_descr).Value
If Not dictTarget.Exists(sKey) Then
dictTarget.Add sKey, lRow
Else
MsgBox "Invalid duplicate key? " & sKey
End If
Next
lNew = lRows
' Run through Orig rows, and write to Orig based on key value
Set rOrig = Worksheets("Orig").Range("A1")
lRows = rOrig.Offset(65000, 0).End(xlUp).Row - rOrig.Row
For lRow = 1 To lRows
sKey = rOrig.Offset(lRow, or_po).Value & "|" & _
rOrig.Offset(lRow, or_partid).Value & "|" & _
rOrig.Offset(lRow, or_descr).Value
If dictTarget.Exists(sKey) Then
' update
lTarget = dictTarget(sKey)
rFinal.Offset(lTarget, fr_comment).Value = rOrig.Offset(lRow, or_comment).Value
rFinal.Offset(lTarget, fr_desired).Value = rOrig.Offset(lRow, or_requested).Value
Else
' new row
lNew = lNew + 1
rFinal.Offset(lNew, fr_partid).Value = rOrig.Offset(lRow, or_partid)
rFinal.Offset(lNew, fr_descr).Value = rOrig.Offset(lRow, or_descr)
rFinal.Offset(lNew, fr_vendorid).Value = rOrig.Offset(lRow, or_vendorid)
rFinal.Offset(lNew, fr_po).Value = rOrig.Offset(lRow, or_po)
rFinal.Offset(lNew, fr_due).Value = rOrig.Offset(lRow, or_balance)
rFinal.Offset(lNew, fr_quantdue).Value = rOrig.Offset(lRow, or_orig)
rFinal.Offset(lNew, fr_status).Value = rOrig.Offset(lRow, or_status)
rFinal.Offset(lNew, fr_orig).Value = ""
rFinal.Offset(lNew, fr_desired).Value = rOrig.Offset(lRow, or_requested)
rFinal.Offset(lNew, fr_comment).Value = rOrig.Offset(lRow, or_comment)
rFinal.Offset(lNew, fr_dayslate).Value = ""
rFinal.Offset(lNew, fr_pri).Value = ""
rFinal.Offset(lNew, fr_shoporder).Value = ""
rFinal.Offset(lNew, fr_remarks).Value = ""
End If
Next
End Sub