For context, I have a google sheet that we use for inventory and pricing. I have made another spreadsheet that imports the ranges that we need from the original to show wholesale inventory to customers without any pricing. I am currently using ImportRange()
to copy the content, but I would like to maintain the formatting of the previous sheet.
I am using this onEdit()
script to update the formatting (I am using a trigger in the original):
function setFormatOnEdit(e) {
if (!e)
throw new Error("This function is automatically called, do not run this manually")
const lock = LockService.getScriptLock()
if (lock.tryLock(350000)) {
try {
const {
master,
sources
} = variables_();
const { range, source } = e;
const { editRange } = sources.find(({ sheetName }) => sheetName == source.getSheetName());
const srcRange = source.getRange(editRange);
const editedSheetName = range.getSheet().getSheetName();
if (editedSheetName != srcRange.getSheet().getSheetName())
return;
//Reformatting Code Here
} catch ({stack}) {
console.error(stack)
} finally {
lock.releaseLock();
console.log("Done");
}
} else { console.error("Timeout") }
}
Currently I am having the issue of e.source returning the first sheet in the source spreadsheet (which is a summary of pricing sheet; I do not want to copy this sheet over) after every edit, regardless of which sheet is edited.
This poses a problem because I am trying to use the sheet name of the edited original to reformat the copy sheet on each edit.
I could just use conditional formatting to reformat the copy, but there are less options possible and I would need to do a search through all rows for certain formatting parameters, which would take forever to update and is just clunky.
Let me know if there is a way to fix this issue, or if there is a better way to do what I am trying to do with copying over.
Nathan Gramm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.