Compare 2 files and add new entries

phitho

New Member
Joined
Aug 26, 2014
Messages
34
I am wondering how I can go about using VBA to compare new entries in one file to an existing file?

I have a ticketing system that I manipulate the raw data to give me a usable file. Rather than take everything from the new file, I just want to copy over the differences (newly added tickets).
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
You haven't specified where anything is on your worksheet so I have assume that one list in in column A of sheet 1 and the second list on column A of sheet 2. This code will find anything which is missing from sheet one which appears on sheet 2 and append it to the bottom of sheet 1 column A
Code:
Sub test()
Dim outarr As Variant


With Worksheets("sheet2")
 lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
 inarr = Range(.Cells(1, 1), .Cells(lastrow, 1))
End With
ReDim outarr(1 To lastrow, 1 To 1)
With Sheet1
 datarow = .Cells(Rows.Count, "A").End(xlUp).Row
 datar = Range(.Cells(1, 1), .Cells(datarow, 1))
 indi = 1
fnd = False
For i = 1 To lastrow
    outarr(i, 1) = ""
    fnd = False
   For j = 1 To datarow
    If inarr(i, 1) = datar(j, 1) Then
     fnd = True
     Exit For
    End If
   Next
 If Not (fnd) Then
  outarr(indi, 1) = inarr(i, 1)
  indi = indi + 1
 End If
Next i
 
  Range(.Cells(datarow + 1, 1), .Cells(datarow + lastrow, 1)) = outarr
End With
End Sub
 
Last edited:
Upvote 0
Sorry for not providing enough details:

- I have a source WB called ticket_export, with a sheet called ticket_export.
- I have a destination WB called KPI with a sheet named ticket_export.
- Column A in both sheets is called Ticket Number
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,147
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top