简体   繁体   中英

Transfer Google Spreadsheet Cell Value generated from ImportRange to another sheet and cell automatically

I have sheet named origin that displays set of data Col A:B via ImportRange I have a sheet named destination

What I wanted to do:

  • When ImportData changes (a new item is added in the origin sheet) I wanted to copy that item and paste it in the destination sheet.

What I dont want to happen:

  • Is copy data that are already existing in the destination sheet.
  • When ImportData Origin is sorted, the display in the origin sheet is also changed. In this case I should still be able to copy data that are not existing in the destination sheet even if both sheets are no longer sorted the same.

Any idea on how I can achieve this? Thank you so much

Explanation:

I would advice you to use a formula in the destination sheet, something like:

UNIQUE(IMPORTRANGE("url", "origin:A1:B"))

so you can have the unique items of the origin sheet in the destination sheet.

The reason that I am suggesting that is because you are looking for a trigger behaviour. Namely, when a new value is added in a cell, grab this value and send it to another spreadsheet. The problem with this approach is that Google-Apps-Script triggers are not triggered by scripts nor formulas, but only by user edits. In other words, if a cell is modified by your import range formula, there is not a direct GAS solution which can figure that out. Only workarounds exist which might have limitations and they are very specific to your exact use case.

Workarounds

  • See this thread for some info and references.

  • You can use the Properties Service which you can store some sort of data that is bound the script. In this way, you can create a Time-driven trigger which will run every 1 minute or so and check if there are changes to the original data. If a new value is added, update the property and send the data to the destination sheet. If no new data is added, do nothing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM