>>405 結構面倒、前提条件として「表A, 表Bのコードは各々ソートされてる」かつ「表A, 表Bのコードは各々の表内で重複してない」のであれば... Type T S As WorkSheet: L As Long: R As Long: C As Long: D As Long: F As Boolean End Type
Dim TA As T, TB As T Set TA.S = WorkSheets("表A"): Set TB.S = WorkSheets("表B") TA.L = TA.S.Cells(TA.S.Rows.Count, 1).End(xlUp).Row: TB.L = TB.S.Cells(TB.S.Rows.Count, 1).End(xlUp).Row TA.R = 1: TB.R = 1 TA.F = False: TB.F = False Dim S As WorkSheet: Set S = WorkSheets("結果") Dim R As Long: R = 1 Do G TA: G TB If TA.F And TB.F And TA.C = TB.C Then S.Cells(R, "A").Value = TA.C: S.Cells(R, "B").Value = TA.D: S.Cells(R, "C").Value = TB.D: TA.F = False: TB.F = False ElseIf (TA.F And TB.F And TA.C < TB.C) Or (TA.F And Not TB.F) Then S.Cells(R, "A").Value = TA.C: S.Cells(R, "B").Value = TA.D: TA.F = False ElseIf (TA.F And TB.F And TB.C < TA.C) Or (Not TA.F And TB.F) Then S.Cells(R, "A").Value = TB.C: S.Cells(R, "C").Value = TB.D: TB.F = False Else Exit Do End If R= R + 1 Loop
Private Sub G(T As T) If Not T.F And T.R <= T.L Then T.C = T.S.Cells(T.R, "A").Value: T.D = T.S.Cells(T.R, "B").Value: T.F = True: T.R = T.R + 1 End If End Sub