Can someone share vba code on how to insert only new data to existing worksheet

Anonymous
2022-12-16T02:52:01+00:00

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

Microsoft 365 and Office | Excel | For business | Windows

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.

0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. Anonymous
    2022-12-16T06:04:53+00:00

    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

    0 comments No comments
  2. Anonymous
    2022-12-16T06:11:37+00:00

    Yes please show me a macro !

    0 comments No comments
  3. Anonymous
    2022-12-16T06:55:53+00:00

    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.

    https://youtu.be/fHFUh6EhBcw

    https://youtu.be/sLW3NbeGDy8

    https://youtu.be/HcfKOusOJhA

    I hope this helps you and gives a solution to your problem

    Regards

    Jeovany

    0 comments No comments
  4. Anonymous
    2022-12-16T08:02:59+00:00


    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.

    0 comments No comments
  5. Anonymous
    2022-12-16T08:27:13+00:00

    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。

    0 comments No comments