Hi sy000,
Greetings! Thank you for posting to Microsoft Community.
It is easy to copy all the data to mater file then use remove duplicate to get the result,
If you still want the macro, I will write it later today.
Best Regards,
Snow Lu
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
hi i am trying to find the VBA code to only copy paste data which are new on one worksheet and copy to another worksheet.
an example below
Jan and Feb data already exist in the master file
now i want only mar and apr (from both file A and B) to be copied into row 8 onwards for another data base purpose
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
Yes please show me a macro !
Hi there
IMHO
For your scenario , requirements and goals Power Query would be the best approach and dynamic solution
Please check the videos below and let us know if you need more help implementing it.
I hope this helps you and gives a solution to your problem
Regards
Jeovany
Sub combinefiles()
'
On Error Resume Next
'---------------for FILE A-------------------------------------
Workbooks("File A.xlsx").Activate
filearows = Sheets("sheet1").Range("A65536").End(xlUp).Row
Workbooks("Master File.xlsx").Activate
fILEMASTERROWS = Sheets("sheet1").Range("A65536").End(xlUp).Row
For i = 2 To filearows
Workbooks("File A.xlsx").Activate
FA1 = Sheets("sheet1").Cells(i, 1)
FA2 = Sheets("sheet1").Cells(i, 2)
FA3 = Sheets("sheet1").Cells(i, 3)
a = FA1 & FA2
Z = 0
For J = 2 To fILEMASTERROWS
Workbooks("Master File.xlsx").Activate
b = Sheets("sheet1").Cells(J, 1) & Sheets("sheet1").Cells(J, 2)
If a = b Then
Z = Z + 1
Else:
End If
Next J
If Z = 0 Then
mASTEROW = Sheets("sheet1").Range("A65536").End(xlUp).Row
Cells(mASTEROW + 1, 1) = FA1
Cells(mASTEROW + 1, 2) = FA2
Cells(mASTEROW + 1, 3) = FA3
Else: End If
Next i
'----------------for FILE B-------------------------------------
filearows = Sheets("sheet1").Range("A65536").End(xlUp).Row
Workbooks("File B.xlsx").Activate
fileBrows = Sheets("sheet1").Range("A65536").End(xlUp).Row
Workbooks("Master File.xlsx").Activate
fILEMASTERROWS = Sheets("sheet1").Range("A65536").End(xlUp).Row
For i = 2 To fileBrows
Workbooks("File B.xlsx").Activate
Fb1 = Sheets("sheet1").Cells(i, 1)
Fb2 = Sheets("sheet1").Cells(i, 2)
Fb3 = Sheets("sheet1").Cells(i, 3)
a = Fb1 & Fb2
Z = 0
For J = 2 To fILEMASTERROWS
Workbooks("Master File.xlsx").Activate
b = Sheets("sheet1").Cells(J, 1) & Sheets("sheet1").Cells(J, 2)
If a = b Then
Z = Z + 1
Else:
End If
Next J
If Z = 0 Then
mASTEROW = Sheets("sheet1").Range("A65536").End(xlUp).Row
Cells(mASTEROW + 1, 1) = Fb1
Cells(mASTEROW + 1, 2) = Fb2
Cells(mASTEROW + 1, 3) = Fb3
Else: End If
Next i
End Sub
Hope it helps.
want only mar and apr (from both file A and B) to be copied into row 8 onwards
how to figure out what are new rows?
from month ?
the macro consolidate all rows looks easier。