0

Thanks in advance for any help! I have a file that produces an output table that also contains a unique key for the set of data. I want to be able to export this data into a CSV file.

That is easy to do I believe, however I would like the code to first check for every row if the item is already there (I have a unique value on every row) and if it is, I would like to rewrite the existing one, if not, I would like to add a new line at the end of the file. Hope I explained it well. Thanks!

1
  • Unclear. Does you have a table for exporting to CSV file, and ALREADY have previous version of CSV file, and you want to merge your table into existing CSV replacing the existing lines with new ones identifying by ID?
    – Akina
    Commented Sep 24, 2019 at 9:37

1 Answer 1

0

The easiest way seems to be:

  1. Import previous version of CSV file into the same worksheet immediately below new data range.
  2. Remove duplicates by identifying column(s) (Data > Data Tools > Remove Duplicates).
  3. Export the result into CSV overwriting its previous version (or rename old, or set new name to new data).

As Microsoft claims in Filter for unique values or remove duplicate values article:

When duplicates are removed, the first occurrence of the value in the list is kept, but other identical values are deleted.

So duplicated rows which are below (i.e. loaded from previous version) will be deleted whereas the most upper duplicate (i.e. new values row for that ID) will remains.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .