素人が組む単純なコードですが、添付図のようなことでよろしければ参考まで。
Shee1、Sheet2共にA列は昇順で並んでいるものとします。
番号の並びがばらばらであるのであれば、昇順に並べ替えての作業を追加して実行する必要があります。
添付図Sheet2のE列は、実行結果を検証しやすいように手動で書込んでいるのでコードとは無関係です。
Sub 加減行削除挿入()
Dim r1 As Long, r2 As Long
Dim myR As Long
With Worksheets(\u0026quot;Sheet1\u0026quot;)
Application.ScreenUpdating = False
myR = 2
For r2 = 2 To Cells(Rows.Count, \u0026quot;A\u0026quot;).End(xlUp).Row
For r1 = myR To .Cells(Rows.Count, \u0026quot;A\u0026quot;).End(xlUp).Row
If Cells(r2, \u0026quot;A\u0026quot;).Value = .Cells(r1, \u0026quot;A\u0026quot;).Value Then
If Cells(r2, \u0026quot;B\u0026quot;).Value = \u0026quot;\u0026quot; And Cells(r2, \u0026quot;C\u0026quot;).Value = \u0026quot;\u0026quot; Then
.Rows(r1).Delete
myR = r1 - 1
Else
.Cells(r1, \u0026quot;B\u0026quot;).Value = .Cells(r1, \u0026quot;B\u0026quot;).Value + Cells(r2, \u0026quot;B\u0026quot;).Value
.Cells(r1, \u0026quot;C\u0026quot;).Value = .Cells(r1, \u0026quot;C\u0026quot;).Value + Cells(r2, \u0026quot;C\u0026quot;).Value
myR = r1 + 1
End If
Exit For
ElseIf Cells(r2, \u0026quot;B\u0026quot;).Value \u0026lt;\u0026gt; \u0026quot;\u0026quot; _
And Cells(2, \u0026quot;C\u0026quot;).Value \u0026lt;\u0026gt; \u0026quot;\u0026quot; _
And Cells(r2, \u0026quot;A\u0026quot;).Value \u0026gt; .Cells(r1, \u0026quot;A\u0026quot;).Value _
And Cells(r2, \u0026quot;A\u0026quot;).Value \u0026lt; .Cells(r1 + 1, \u0026quot;A\u0026quot;).Value Then
.Rows(r1 + 1).Insert Shift:=xlDown
.Range(.Cells(r1 + 1, \u0026quot;A\u0026quot;), .Cells(r1 + 1, \u0026quot;C\u0026quot;)).Value _
= Range(Cells(r2, \u0026quot;A\u0026quot;), Cells(r2, \u0026quot;C\u0026quot;)).Value
myR = r1 + 1
Exit For
ElseIf Cells(r2, \u0026quot;B\u0026quot;).Value \u0026lt;\u0026gt; \u0026quot;\u0026quot; _
And Cells(r2, \u0026quot;C\u0026quot;).Value \u0026lt;\u0026gt; \u0026quot;\u0026quot; _
And r1 = .Cells(Rows.Count, \u0026quot;A\u0026quot;).End(xlUp).Row Then
.Range(.Cells(r1 + 1, \u0026quot;A\u0026quot;), .Cells(r1 + 1, \u0026quot;C\u0026quot;)).Value _
= Range(Cells(r2, \u0026quot;A\u0026quot;), Cells(r2, \u0026quot;C\u0026quot;)).Value
End If
Next r1
Next r2
End With
Application.ScreenUpdating = True
End Sub