Reputation: 45
I am trying to modify an existing Google Sheet using a Form response sheet. Suppose in the sheet I need modified I have column G called "Annotated Asset ID" which contains a list of asset IDs. Now in the form response sheet there are two columns; Old ID (D) and New ID (E). I would like to check Column G of the existing sheet to see if it contains the Old ID and if it does I need to replace it with the New ID.
What is a good way to do this?
Form Response:
Existing Sheet:
Upvotes: 1
Views: 875
Reputation: 15377
You can do this with Apps Script.
const cell = sheet.getRange("G1:G").createTextFinder("old-id").findNext()
if (cell) { cell.setValue("new-id") }
function replaceIds() {
const ss = SpreadsheetApp.getActiveSpreadsheet()
const formResponseSheet = ss.getSheetByName("response-sheet-name")
const existingSheet = ss.getSheetByName("existing-sheet-name")
const oldIds = formResponseSheet.getRange("D1:D").getValues().flat()
const newIds = formResponseSheet.getRange("E1:E").getValues().flat()
const rangeToCheck = existingSheet.getRange("G1:G")
oldIds.forEach(function(id, index) {
let cell = rangeToCheck.createTextFinder(id).findNext()
if (cell) {
cell.setValue(newIds[index])
}
})
}
Tools > Script editor
menu item. Make sure to change the response sheet nad existing sheet names.Upvotes: 1