troubleshooting Question

Google Sheets script, find next row

Avatar of Zac
ZacFlag for United Kingdom of Great Britain and Northern Ireland asked on
VB ScriptGoogleGoogle WorkspaceScripting Languages
7 Comments1 Solution136 ViewsLast Modified:
Hello, I have the following script for a google sheets. I would like the row of data to be copied down to the next available (empty) row and then the original data to be cleared, ready for the the next input.

function saveButton() {
  var ss = SpreadsheetApp.getActive();
  // [START modifiable parameters]
  var sourceRange = ss.getRange('Active Jobs!A2:F2');
  var targetRange = ss.getRange('Active Jobs!A3:F3');
  // [END modifiable parameters]
  sourceRange.copyTo(targetRange);
  ss.toast('Data copied to ' + targetRange.getSheet().getName() + '. ' +
    'To undo, press Control+Z (on a Mac, ⌘Z).', 'Action button - Save');

  var ss = SpreadsheetApp.getActive();
  // [START modifiable parameters]
  var rangeToClear = ss.getRange('Active Jobs!A2:F2');
  // [END modifiable parameters]
  rangeToClear.clearContent();
  ss.toast("Cleared range '" + rangeToClear.getSheet().getName() + "'!" + rangeToClear.getA1Notation() + '. ' +
    'To undo, press Control+Z (on a Mac, ⌘Z).', 'Action button - Clear');
  rangeToClear.activate();
}


I have two problems:

1, var targetRange = ss.getRange('Active Jobs!A3:F3');

this line needs to read... in plain english..... find the last available row and insert



2, The delete does not seem to clear the last visited cell. So the last cell that the user inputs into is F2. If the user does not click out of that cell before pressing save then this cell is ignored.

thanks for your help.

https://docs.google.com/spreadsheets/d/1qSauIqjvSEhEEZJ6z4pJUnR_HZcoMi98frAx94zl6a8/edit?usp=sharing
ASKER CERTIFIED SOLUTION
Zac

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros