'同形の表をまとめるマクロ '元のシート、更新シート1、更新シート2、というシートがあるという例です。 '更新シート1と2は元のシートのコピーに対して別々に更新追加を行った 'ものです。これらの変更を元のシートに対して行い、Sheet4へ出力します。 'さらに、Sheet5には更新ログ、Sheet6には追加ログを出力します。 ' Sheet1(元のシート) ' | A | B | C | ' ---+--------+--------+--------+ ' 1 | Field1 | Field2 | Field3 | ' 2 | 1 | 1 | 1 | ' 3 | 2 | | | ' 4 | 3 | | | ' ' Sheet2(更新シート1) ' | A | B | C | ' ---+--------+--------+--------+ ' 1 | Field1 | Field2 | Field3 | ' 2 | 1 | 1 | 1 | ' 3 | 2 | 2 | | ' 4 | 3 | | | ' 5 | 4 | 4 | 4 | ' ' Sheet3(更新シート2) ' | A | B | C | ' ---+--------+--------+--------+ ' 1 | Field1 | Field2 | Field3 | ' 2 | 1 | 1 | 1 | ' 3 | 2 | | 3 | ' 4 | 3 | | 3 | ' 5 | 4 | 4 | 4 | Option Explicit Const shtOutput = -3 Const shtLogUpdate = -2 Const shtLogAdd = -1 Const shtOld = 0 Sub MySheetMergeTest() Dim a(shtOutput To 2) As Object 'シートの割り当て Set a(shtOutput) = Sheets("Sheet4") Set a(shtLogUpdate) = Sheets("Sheet5") Set a(shtLogAdd) = Sheets("Sheet6") Set a(shtOld) = Sheets("Sheet1") Set a(1) = Sheets("Sheet2") '更新シート1 Set a(2) = Sheets("Sheet3") '更新シート2 a(shtOutput).Select Application.ScreenUpdating = False MySheetMerge a End Sub Sub MySheetMerge(a As Variant) Dim ROWMAX As Long Dim oldRows As Long, updateCount As Long, addCount As Long Dim rngData As Range, rngUpdate As Range, rngAdd As Range Dim r As Range, rngOutput As Range Dim i As Integer ROWMAX = a(shtOutput).Rows.Count '結果出力用シートへ元のシートのデータをコピー a(shtOld).Cells.Copy a(shtOutput).Cells(1, 1) '更新ログ用シートの初期化 a(shtLogUpdate).Cells.Clear a(shtLogUpdate).Range("A1:D1").Value _ = Array("アドレス", "シート", "更新前", "更新後") '追加ログ用シートの初期化 a(shtLogAdd).Cells.Clear a(shtLogAdd).Cells(1, 1).Value = "シート" a(shtOld).Cells(1, 1).CurrentRegion.Rows(1).Copy _ a(shtLogAdd).Cells(1, 2) '元のデータ件数を取得 oldRows = a(shtOld).Cells(1, 1).CurrentRegion.Rows.Count updateCount = 0 addCount = 0 For i = 1 To UBound(a) '更新シートのデータ範囲の取得 Set rngData = a(i).Cells(1, 1).CurrentRegion '更新データ範囲の取得 If oldRows > 1 Then Set rngUpdate = Application.Intersect(rngData, _ a(i).Rows(1).Resize(oldRows - 1).Offset(1)) End If '追加データ範囲の取得 Set rngAdd = Application.Intersect(rngData, _ a(i).Rows(oldRows + 1).Resize(ROWMAX - oldRows)) '更新処理 If Not (rngUpdate Is Nothing) Then For Each r In rngUpdate.Cells Set rngOutput = a(shtOutput).Cells(r.Row, r.Column) If r.Value <> a(shtOld).Cells(r.Row, r.Column).Value Then '更新ログの出力 updateCount = updateCount + 1 With a(shtLogUpdate).Cells(updateCount + 1, 1) .Value = r.Address(False, False) .Cells(1, 2).Value = a(i).Name .Cells(1, 3).Value = rngOutput.Value .Cells(1, 4).Value = r.Value End With '更新 rngOutput.Value = r.Value End If Next End If '追加処理 If Not (rngAdd Is Nothing) Then rngAdd.Copy '追加 a(shtOutput).Cells(oldRows + addCount + 1, 1) _ .PasteSpecial xlValues '追加ログの出力 With a(shtLogAdd).Cells(addCount + 2, 2) .PasteSpecial xlValues .Cells(1, 0).Value = a(i).Name End With Application.CutCopyMode = False addCount = addCount + rngAdd.Rows.Count End If Next End Sub