|
後、ついでですが?
もし、Book1のA列とBook2のA列が共に昇順整列されているなら
もう少し速くする事が出来ます
尚、A列の値が半角英数以外の文字が入るなら
モジュール先頭に以下のコードを記述して下さい
(Excelの整列順とVBAの整列順が違う為)
Option Explicit
Option Compare Text 'これ
Sub Test_2()
' 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
Dim lngAppend As Long, lngStart As Long
Set Bk1 = ThisWorkbook
Set Bk2 = Workbooks.Open(ThisWorkbook.Path & "\Book2.xlsx")
With Bk1.Worksheets("sheet1")
LstR1 = .Cells(Rows.Count, 1).End(xlUp).Row
lngAppend = LstR1 + 1
LstR2 = Bk2.Sheets("sheet1").Cells(Rows.Count, 1).End(xlUp).Row
lngStart = 1
For i = 1 To LstR2
For k = lngStart 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(lngAppend, 1)
lngAppend = lngAppend + 1
Else
lngStart = k + 1
End If
Next i
End With
Bk2.Close True
Bk1.Save
End Sub
|
|