Reputation: 1
I am a beginner in script google code. And now I have a problem with my code when I make a trigger in my spreadsheet. I have this code
function moveValuesOnly () {
var ss = SpreadsheetApp.getActiveSpreadsheet ();
var source = ss.getRange ("Sheet1!B6:V9");
var destRange = ss.getRange("Sheet1!B11:V14");
var persamaan = ss.getRange("Sheet1!V6:V9")
var nilai = ss.getRange("Sheet1!Z1").getValues
// Déterminer l'emplacement de la première ligne vide.
if(
persamaan.getValues() == nilai
)
{
source.copyTo (destRange, {contentsOnly: true});
source.clear ();
}
}
and I have this link for my spreadhseet https://docs.google.com/spreadsheets/d/1vhg8CRF1GWS9y300Bct3He1zm__hP9tCFGBOI86NiZs/edit?usp=sharing
In my spreadsheet I have range for B6 to V9. I want to make a trigger when the value of each V in V6 - V9 = 'Lulus' then check if B11 has a value so the B6 until V6 value copy in B12 but if B11 didn't have value so B6 until V6 value copy in B11.
Upvotes: 0
Views: 168
Reputation: 18784
You probably do not need a time-driven trigger but an onEdit(e)
simple trigger. Try this:
function onEdit(e) {
const sheetToWatch = 'Sheet1';
const columnToWatch = 22; // column V
const valueToWatch = 'Lulus';
if (!e) {
throw new Error('Please do not run the script in the script editor window. '
+ 'It runs automatically when you hand edit the spreadsheet');
}
const sheet = e.range.getSheet();
if (!e.range
|| e.value !== valueToWatch
|| e.range.columnStart !== columnToWatch
|| e.range.rowStart <= sheet.getFrozenRows()
|| sheet.getName() !== sheetToWatch) {
return;
}
const values = sheet.getRange(e.range.rowStart, 1, 1, sheet.getLastColumn())
.getValues()
.flat();
sheet.appendRow(values);
sheet.deleteRows(e.range.rowStart, 1);
}
Some of the best resources for learning Google Apps Script include the Beginner's Guide, the New Apps Script Editor guide, the Fundamentals of Apps Script with Google Sheets codelab, the Extending Google Sheets page, javascript.info, Mozilla Developer Network and Apps Script at Stack Overflow.
Upvotes: 1