|
こんなのでは?
Sub Test()
' Dim i As Integer, k As Integer
Dim i As Long, k As Long
Dim LstR1 As Long, LstR2 As Long, Bk1 As Workbook, Bk2 As Workbook
Set Bk1 = ThisWorkbook
Set Bk2 = Workbooks.Open(ThisWorkbook.Path & "\Book2.xlsx")
With Bk1.Worksheets("sheet1")
LstR1 = .Cells(Rows.Count, 1).End(xlUp).Row
LstR2 = Bk2.Sheets("sheet1").Cells(Rows.Count, 1).End(xlUp).Row
' For k = 1 To LstR1
' For i = 1 To LstR2
' If .Cells(k, 1).Value <> Bk2.Sheets("sheet1").Cells(i, 1).Value Then
' Exit For
' End If
' Next i
' Next k
' If k > LstR2 Then
' Bk2.Sheets("sheet1").Cells(i, 1).Copy .Cells(Rows.Count, 1).End(xlUp).Offset(1)
' End If
For i = 1 To LstR2
For k = 1 To LstR1
If .Cells(k, 1).Value = Bk2.Sheets("sheet1").Cells(i, 1).Value Then
Exit For
End If
Next k
If k > LstR1 Then
Bk2.Sheets("sheet1").Cells(i, 1).Copy .Cells(Rows.Count, 1).End(xlUp).Offset(1)
End If
Next i
End With
Bk2.Close True
Bk1.Save
End Sub
|
|