Hi guys,
I would like to compare two workbooks by row. If data does not exist in another workbook,then the data which exist needs to be transferred to another row by row to the next blank row in another workbook. May I know how can I get this done?
Thanks in advance.
I would like to compare two workbooks by row. If data does not exist in another workbook,then the data which exist needs to be transferred to another row by row to the next blank row in another workbook. May I know how can I get this done?
Thanks in advance.
Code:
Sub abc()
Dim LastRow As Long
Dim i As Integer
Dim erow As Long
Dim wb1 As Workbook
Dim ws1 As Worksheet
Dim wb2 As Workbook
Dim wb As Workbook
Set wb1 = Workbooks.Open(Filename:="C:\Users\maggie\Desktop\florence.xlsx")
Set ws1 = wb1.Sheets("Sheet1")
Set wb2 = Workbooks("fortest.xlsx")
LastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
For i = 4 To LastRow
If wb2.Sheets("Sheet1").Cells(i, 2) = "Sheet1" Then
Range(Cells(i, 1), Cells(i, 4)).Select
Selection.Copy
Dim p As Integer, q As Integer
p = Worksheets.Count
For q = 1 To p
If ActiveWorkbook.Worksheets(q).Name = "Sheet1" Then
Worksheets("Sheet1").Select
End If
Next q
erow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
wb2.Sheets("Sheet1").Range("A1:A7").Copy
Set wb = ThisWorkbook
wb.Activate
ActiveSheet.Paste Destination:=Worksheets("Sheet1").Range("C" & erow) 'Cells(erow, 1).Select
'ActiveSheet.Paste
'ActiveWorkbook.Save
'ActiveWorkbook.Close
'Application.CutCopyMode = False
End If
Next i
wb1.Close
End Sub