I am trying to migrate from Microsoft Excel to Google sheets in order for the company to work from any work station.
I want to compare two ranges of data, one in one column and the other in another column.
- If the cell value in the first range equals the cell value in the second range, then I want it to...
- Add the value from the second range to the first range in the matching cell and continue checking the rest of the range.
I have done this easily in VBA but I am having a hard time doing it in Goole Sheets.
For now the code in Google Sheets does the following:
If it finds a matching value between the two ranges it adds the value to the every single cell in the first range.
Here is what my code looks like:
function myFunction() {
var pr = SpreadsheetApp.openById("my spreadsheet");
var sheet = pr.getSheetByName("sheet1");
var sheet1 = pr.getSheetByName("sheet1");
var cell = sheet.getRange('J3:J95');
var cell1 = sheet1.getRange('C3:C1125');
if(cell1.getValue()===cell.getValue()) {
cell1.offset(0, 2).setValue(cell1.offset(0, 2).getValue() + cell.offset(0, 1).getValue())
}
}

