google-spreadsheet


run onedit on active sheet


I have looked for an answer for this question, but I am exceptionally green to even rudimentary scripting so I have not been able to understand what I have found.
I have a spreadsheet we are using for a worklist - it is separated into three tabs: Samples / Images / Archive
Users access the spreadsheet to collect items to work - once it is complete they mark Column A as "Complete", and I have code very helpfully provided by ScampMichael to automatically move the row to the "Archive" sheet once they do so:
function onEdit(event) {
// assumes source data in sheet named Samples
// target sheet of move to named Archive
// test column with Completed is col 1 or A
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = event.source.getActiveSheet();
var r = event.source.getActiveRange();
if(s.getName() == "Samples" && r.getColumn() == 1 && r.getValue() == "Complete") {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Archive");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).moveTo(target);
s.deleteRow(row);
}
}
My challenge is that I can not get this code to work simultaneously for both the "Samples" and the "Images" tab. I gather that this is because you can not have more than one onEdit function per spreadsheet, but so far my efforts to expand the code to look at both tabs has failed.
Any help that can be provided is extremely appreciated!
It is still not exactly clear what you want to do, but I took a shot at it. I assumed the image is on the same row number as the completed row on samples and when copying the image to archive I append it to the end of the row created in the archive. I made some changes to your code. They are noted. If you need it, I can share my testing spreadsheet.
function onEdit(event) {
// assumes source data in sheet named Samples
// target sheet of move to named Archive
// test column with Completed is col 1 or A
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = event.source.getActiveSheet();
var r = event.source.getActiveRange();
if(s.getName() == "Samples" && r.getColumn() == 1 && r.getValue() ==
"Complete") {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Archive");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).moveTo(target);
s.deleteRow(row);//changed to delete the row
image(row,numColumns)//call function to process Images send row and last column
}}
function image(row,numColumns){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s1=ss.getSheetByName("Images")//get Images sheet
var lc=s1.getLastColumn()
var data=s1.getRange(row, 1, 1,lc)//get row
var targetSheet = ss.getSheetByName("Archive");
var target = targetSheet.getRange(targetSheet.getLastRow() , numColumns+1,1,1);//add image one column after Samples data on same row.
s1.getRange(row, 1, 1, lc).moveTo(target);
s1.deleteRow(row)//delete the copied image row.
}

Related Links

Google Sheets doc incorrect?
Why does the “continue” command appear on some google sheets but not others
Date converted to plain text in google spreadsheet
How can I create a dynamic link between e-days holiday data and Google Sheets?
Google Sheets ArrayFormula with Sumifs
How to put a new column after a “sort” in a google sheets doc?
How can I add footers to Google spreadsheet?
Amazon price in Google Spreadsheets
Using Array Formula with Split()
How do I stop google sheets reassigning formulae values on another sheet
Google Spreadsheet Function That Sums Numbers In A Column When the Row Contains An EXACT Text
Change background color in cell depending on another cell value
How to insert an IF statement that involves text with script?
Google Sheets Lookup Tool Assistance
Conditionally add items to a drop-down list
Google Sheets IF OR statement

Categories

HOME
delphi-7
gpu
ns-3
powerpoint
toolbox
solaris
carousel
big-o
pearson-correlation
polling
google-admin-sdk
angularfire2
opengl-3
g++
pcl-crypto
enthought
pega
rtf
filechannel
spring-social
stellar.js
linear-algebra
intershop
android-7.0-nougat
google-content-api
google-container-registry
soci
gmm
replication
asciidoctor-pdf
react-toolbox
roslyn
imageresizer
aggregation
tosca
direct3d11
xunit
beautifier
opentk
wcag
gp
sqsh
mockjax
deltaspike
dumpbin
biztalk-rule-engine
hunspell
hibernate-search
mnist
batching
swagger-php
watchman
ideascript
protein-database
naming
subclipse
oracle-service-bus
contract
xmldocument
procfile
cnc
hammer.js
spring-integration-sftp
singleinstance
dt
reshape
type-theory
java-websocket
objectscript
rsa-archer-grc
pocketsphinx-android
cronexpression
angular2-testing
hadoop-2.7.2
latin
neon
jodd
drawstring
jboss-tools
lean
refinerycms
turbo-prolog
iokit
canalyzer
sony-lifelog-api
cakephp-2.7
gamekit
rapidsvn
big-ip
punycode
cocos3d
jqmodal
angular-carousel
template-deduction
grails-domain-class
visual-studio-express
artemis
model-driven-development
route-provider
scmmanager
node-blade
apache-abdera
device-width
dopostback
boost-msm
inkcanvas
google-floodlight
codebase
instantiationexception
easyb
binomial-heap
zend-rest
linfu-dynamicproxy
httpcookie
leader

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App