I'm so close!
In short, when I find a value in Workbook B that isn't found in Workbook A, then I want to copy some cells in that row into the next available row in Workbook A.
The problem is the paste part. I can get the rows copied and the destination cell selected, but whenever I try to paste it using Selection.Paste, I get this error: Object doesn't support this property or method.
What is the solution, please?
In short, when I find a value in Workbook B that isn't found in Workbook A, then I want to copy some cells in that row into the next available row in Workbook A.
The problem is the paste part. I can get the rows copied and the destination cell selected, but whenever I try to paste it using Selection.Paste, I get this error: Object doesn't support this property or method.
What is the solution, please?
Code:
Sub CopyFromCSV()
Application.ScreenUpdating = False
Dim i, x As Integer
Dim sourcebook As Workbook
Dim alphabook As Workbook
Dim expdata As Worksheet
Dim legacy As Worksheet
Dim sFileName As String
Dim legacyTrans As String
Dim searchRng As Range
sFileName = Application.GetOpenFilename(, , "Select a CSV file for import")
Set sourcebook = Workbooks.Open(sFileName)
Set expdata = sourcebook.Worksheets("Export")
Set alphabook = Application.ThisWorkbook
Set legacy = ThisWorkbook.Worksheets("Legacy - Checking")
'WHERE IS THE NEXT AVAILABLE ROW ON LEGACY PROPER
For i = 1 To 5000
If legacy.Cells(i, 17).Value = "" Then
x = i
Exit For
End If
Next i
For i = 5 To 500
Set searchRng = legacy.Range("Q:Q").Find(expdata.Cells(i, 1))
If searchRng Is Nothing Then
expdata.Range("A" & expdata.Cells(i, 1).Row & ":I" & expdata.Cells(i, 1).Row).Copy
legacy.Activate
legacy.Cells(x, 17).Select
[COLOR=#ff0000]Selection.Paste[/COLOR]
Exit For
End If
Next i
End Sub