I’m facing a developent problem trying to compare two datatables.
Data tabels have different columns but the one to compare is the same.
The first datatable is complete with full address and the second one has the post office and postcode, for example. Both datatables have a column called PostCode.
If the postcode in the big datatable (with the full address) isn’t present in the second datatable (the one with City and Postcode only), then I need to write it to a third datatable to then be added to the second datatable, or write it directly in case it’s possible.
If there’s a match nothing needs to be done because the postcode already belongs to the datatable. The idea is to always have the list of postcodes updated with all the used postcodes.
I can’t share the data I’m using. I created the fictional headers for that reason.
But we can imagine that there’s a list of addresses in which I need to check if the postcode exists in the postcode list. If it doesn’t exist, I need to update the postcode list.
I’ve created a unique datatable containing the postcodes from the main datatable to loop it through the postcode list. The result though isn’t correct.
1. Read Range (Datatable1) Output: dt1
2. Read Range (Datatable2) Output: dt2
3. Build DataTable (dt3) with the same headers as dt1
4. For Each row in dt1
5. Assign: postcode = row("Postcode").ToString()
6. If Not dt2.AsEnumerable().Any(Function(x) x("Postcode").ToString() = postcode)
7. Add DataRow to dt3 (row.ItemArray)
8. Write Range (dt3) Output: ThirdDataTable.xlsx