'Find value in another spreadsheet and replace another

I have to keep track of oil changes of the fleet. My sheet contains a column of the vehicle tag, date and mileage of the latest oil change, its current one, and it has formulas to calculate how many kilometers they have left. We update by downloading the fuel report, which collects their mileage as well, and manually pasting them one by one.

I would like to run a script that looks up for the tag, then replaces the mileage. Note that we currently have over 400 lines of equipment to update, which is why I'd appreciate this being solved.

The logic I'm thinking is:

Sheet 1

TAG1 | 10
TAG2 | 20
TAG3 | 30
TAG4 | 40

Sheet 2

TAG1 | 15
TAG2 | 25
TAG4 | 45

Note that in the second file I skipped TAG3, which replicates the occurence (the lines aren't fixed).

Intended result:

  • Google Sheets follows (SHEET 1, COLUMN A), looks up TAG1 on (SHEET 2, COLUMN A);
  • If TAG1 is found, localizes MILEAGE on (SHEET 2, COLUMN B) in the same line and replaces on (SHEET 1, COLUMN B);
  • If TAG1 isn't found, skips to next line and repeats.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source