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 - Lookup - Multiple lookups, with IF and OFFSET's
Google Scripts - Add todays date in specific cell, but ignore updating cell again if overtyped
How to distinguish between a Google Doc and Spreadsheet with the URL?
Google Speadsheet: ArrayFormula and Filter
Query by blank / not blank parameter
Change text format on piecharts in google sheets api
Compare dates in WHERE request within QUERY in GoogleSheets
Referencing current cell, but from different worksheet
Google spreadsheet: Search data in a range (multiple column & row) and return multiple available results
Google Sheets API V4 - Autofill Error - No grid with id: 0
Google sheets text date conversion
Google Sheets Coding by column NAME not letter/number?
Deleting random letters from Google Spreadsheets
Countif returning 1 count while the cell contains 2
Google Sheets formula to change a cells value based on another cells value
Query Removes Date Values

Categories

HOME
scikit-learn
merge
numbers
obfuscation
saml-2.0
jwplayer
composite-primary-key
package
knitr
echo
vert.x
boto3
discrete-mathematics
ipmitool
radgridview
intershop
red5
easyphp
identity-management
oledb
lilypond
articulate-storyline
postscript
inno-download-plugin
joptionpane
exit
android-things
constexpr
dotspatial
postback
installshield-le
carriage-return
installscript
reverse
batching
searchkit
contract
signal-strength
jide
hammer.js
context-switch
mathcad
ampps
slackware
redbeard-ios
microstation
qtplugin
resourcemanager
rspec2
udpclient
appscale
clipboard.js
cassia
cda
uiactionsheet
aspen
exim4
concept-insights
custom-errors
gocql
dllimport
rewrite
jdi
poppler
zen-cart
rpart
git-ftp
procedural-programming
at-job
webmatrix-3
beatsmusic
crowd
deform
rmysql
trdion2011
matrix-inverse
ray
cfcache
android-audiorecord
solace-mq
ie8-compatibility-mode
cnf
font-awesome-4.0.0
bjyauthorize
sqlclr
curb
qtconcurrent
web-farm
zope.interface
dajaxice
cuda-gdb
extconf.rb
appjs
convention
entity-attribute-value
tournament
nhprof
lobo-cobra
firefox-3
flvplayback
appliance

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App