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

GoogleFinance - Remove USD Symbol
How do I generate a link that requests access to read non-public sheet using the google-drive api?
How can I SUM alphanumeric values in Google Sheets?
How to use ArrayFormula in Google Sheets, with multiple IF conditions?
Google Sheet Query - Group / concatenate multiple rows
How do I delete menu item created by createAddonMenu() in Google Script
Google spreadsheet copy column with =DATEVALUE()
Compare the values in two Google worksheets in the same document
Google Sheets- Formula parse error with all formulas
How to use a formula written as a string in another cell [evaluate for Google Spreadsheet]
In google sheets, conditional formatting, need custom formula that looks for range between 2 values
Automatically Update Formula in Google Sheets so that it calculates difference between two adjacent columns with weekly updated values
Sort an imported table as a 2 column table in Google Spreadsheets
Stacking multiple query output in one sheet
Delete expired rows
How to prevent automatic truncation of leading zeros in google spreadsheet

Categories

HOME
django
checkstyle
case
pascal
permissions
hpc
character
reactive-programming
siddhi
alamofire
parameter-passing
gruntfile
production
cfml
selinux
simpleitk
dpdk
named-entity-recognition
definitelytyped
fable-f#
angular-translate
twiml
jett
twos-complement
fossil
sql-delete
alphabetical
railstutorial.org
magento-1.9.3
trigonometry
laravel-elixir
android-checkbox
drupal-theming
stylecop
facebook-social-plugins
phpdbg
httrack
libgphoto2
openal
context-sensitive-grammar
trigger.io
rocks
node-request
tinkerpop3
nikeplus-api
model-associations
tooleap
gogs
kango-framework
turbo-prolog
asyncdisplaykit
jnlua
dynatree
grgit
fiware-monitoring
google-books
pax-exam
ember-cli-rails
zscript
canvg
procedural-programming
adehabitathr
variadic-templates
packet-sniffers
functional-java
mt4j
gd-graph
solace-mq
rolify
merb
bjyauthorize
subgraph
stress
convention
user-tracking
jquery-tools
mbeans
cac
burndowncharts
dsl-tools
alsb
dsoframer

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