Google Sheets run the script in all sheets - google-apps-script

I am trying to implement the following function on Open sheet but I want to change the tab color on all the sheets. With this function, it allows me to change color only to single tab.
function getFirstEmptyRow() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheetname = "Section A";
var sheet = ss.getSheetByName(sheetname);
var column = sheet.getRange('F:F');
var values = column.getValues(); // get all data in one call
var ct = 0;
while ( values[ct][0] != "" ) {
ct++;
}
Logger.log("Row "+ ct);
var ax=sheet.getRange(ct, 7).getValue();
if(ax == ""){
sheet.setTabColor("ff0000")
} else {
sheet.setTabColor(null)
}
}

Try this:
function onOpen() {
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
sheets.forEach(s => s.setTabColor("ff0000"));
}
It hard to tell from the provided code, probably you need this:
function onOpen() {
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
for (var sheet of sheets) {
var data = sheet.getDataRange().getValues(); // get all data
var col_G = data.map(x => x[6]); // get column G
var last_cell = col_G.pop(); // get last cell of column F
if (last_cell == '') sheet.setTabColor("ff0000");
}
}
Or even shorter:
function onOpen() {
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
for (var sheet of sheets) {
var data = sheet.getDataRange().getValues();
if (data.pop()[6] == '') sheet.setTabColor("ff0000");
}
}
It will make a tab red if in last row that of the table the cell in column G is empty.
If you have several sheets that you want to change you can filter them by names this way:
var names = ['Sheet1', 'Sheet2', 'Sheet3'];
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
sheets = sheets.filter(s => names.includes(s.getName()));
// the rest of a code

I'm assuming you want to change the tab color for all sheets if the value in column F of the last row of any sheet is blank. There are other values in that row. I've include onOPen, onEdit and onChange.
function onOpen(e) {
// onOpen is a simple trigger and doesn't need to be installed
// don't really use e in this scenario
getFirstEmptyRow();
}
function onEdit(e) {
// onEdit is a simple trigger and doesn't need to be installed
var sheet = e.range.getSheet();
if( e.range.getRow() === sheet.getDataRange().getLastRow() ) {
if( e.range.getColumn() === 6 ) {
if( e.value === "" ) getFirstEmptyRow();
}
}
}
function onChange(e) {
// onChange is an installed trigger
// don't really use e in this scenario
getFirstEmptyRow();
}
function getFirstEmptyRow() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheets = ss.getSheets();
var i=0;
var sheet = null;
var value = null;
var color = null;
for( i=0; i<sheets.length; i++ ) {
sheet = sheets[i];
value = sheet.getRange(sheet.getDataRange().getLastRow(),7).getValue();
color = value === "" ? "ff0000" : null;
sheet.setTabColor(color);
}
}

Related

How to allow non-sheet owners run scripts that involve protected cells

I have the script below where some cells are protected because they contain formula but I can script linked to buttons that when executed, it updates the cell values in these protected cells, this is fine if you are the sheet owner but if you are not you get a error saying 'You are editing protected cells....'
I have seen some solutions where the script has been deployed as a web app and then set so it always runs as the owner but can't get this working for my use case, I deployed and set as to always run as me but this only seems like half the solution?
My code is below:
//
// Save Data
function submitData() {
var SPREADSHEET_NAME = "Data";
var SEARCH_COL_IDX = 0;
var RETURN_COL_IDX = 0;
var ss = SpreadsheetApp.getActiveSpreadsheet();
var formSS = ss.getSheetByName("Tool"); //Form Sheet
var datasheet = ss.getSheetByName("Data"); //Data Sheet
var str = formSS.getRange("A10").getValue();
var values = ss.getSheetByName(SPREADSHEET_NAME).getDataRange().getValues();
for (var i = 0; i < values.length; i++) {
var row = values[i];
if (row[SEARCH_COL_IDX] != str ) {
//SpreadsheetApp.getUi().alert(' "Dmp #' + formSS.getRange("A4").getValue() + ' "');
// return row[RETURN_COL_IDX];
//} else {
//Input Values
var values1 = [[formSS.getRange("A10").getValue(),
formSS.getRange("B10").getValue(),
formSS.getRange("C10").getValue(),
formSS.getRange("D10").getValue(),
formSS.getRange("E10").getValue(),
formSS.getRange("F10").getValue(),
formSS.getRange("G10").getValue(),
formSS.getRange("H10").getValue(),
formSS.getRange("I10").getValue(),
formSS.getRange("J10").getValue(),
formSS.getRange("K10").getValue()]];
var values2 = [[formSS.getRange("A10").getValue(),
formSS.getRange("B10").getValue(),
formSS.getRange("C10").getValue(),
formSS.getRange("D10").getValue(),
formSS.getRange("E10").getValue(),
formSS.getRange("F10").getValue(),
formSS.getRange("G10").getValue(),
formSS.getRange("I10").getValue(),
formSS.getRange("J10").getValue(),
formSS.getRange("K10").getValue()]];
values2[0].forEach(function(val) {
if (val === "") {
throw new Error("Please fill in Project, Category, Subsystem, Description and Created By Fields.");
}
})
// Save New Data
datasheet.getRange(datasheet.getLastRow()+1, 1, 1, 11).setValues(values1);
SpreadsheetApp.getUi().alert(' New Record Created ');
formSS.getRange("D10").clearContent();
formSS.getRange("E10").clearContent();
formSS.getRange("F10").clearContent();
formSS.getRange("G10").clearContent();
formSS.getRange("H10").clearContent();
formSS.getRange("I10").clearContent();
formSS.getRange("J10").setValue(new Date())
return row[RETURN_COL_IDX];
}
}
}
//=========================================================
// Clear form
function clearCell() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var formSS = ss.getSheetByName("Tool"); //Form Sheet
formSS.getRange("D10").clearContent();
formSS.getRange("E10").clearContent();
formSS.getRange("F10").clearContent();
formSS.getRange("G10").clearContent();
formSS.getRange("I10").clearContent();
formSS.getRange("J10").setValue(new Date())
return true ;
}
//=====================================================================
var SPREADSHEET_NAME = "Data";
var SEARCH_COL_IDX = 0;
var RETURN_COL_IDX = 0;
function searchStr() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var formSS = ss.getSheetByName("Tool"); //Form Sheet
var str = formSS.getRange("F4").getValue();
var values = ss.getSheetByName(SPREADSHEET_NAME).getDataRange().getValues();
for (var i = 0; i < values.length; i++) {
var row = values[i];
if (row[SEARCH_COL_IDX] == str) {
formSS.getRange("A6").setValue(row[0]) ;
formSS.getRange("B6").setValue(row[1]);
formSS.getRange("C6").setValue(row[2]);
formSS.getRange("D6").setValue(row[3]);
formSS.getRange("E6").setValue(row[4]);
formSS.getRange("F6").setValue(row[5]);
formSS.getRange("G6").setValue(row[6]);
formSS.getRange("H6").setValue(row[7]);
formSS.getRange("I6").setValue(row[8]);
formSS.getRange("J6").setValue(row[9]);
return row[RETURN_COL_IDX];
}
}
}
//===================================================================
function rowDelete() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var formSS = ss.getSheetByName("Tool"); //Form Sheet
var datasheet = ss.getSheetByName("Data"); //Data Sheet
var ui = SpreadsheetApp.getUi();
var response = ui.alert(
'Are you sure you want to delete this record?',
ui.ButtonSet.YES_NO);
// Process the user's response.
if (response == ui.Button.YES) {
var str = formSS.getRange("F4").getValue();
var values = ss.getSheetByName(SPREADSHEET_NAME).getDataRange().getValues();
for (var i = 0; i < values.length; i++) {
var row = values[i];
if (row[SEARCH_COL_IDX] == str) {
var INT_R = i+1
datasheet.deleteRow(INT_R) ;
formSS.getRange("A6").clearContent();
formSS.getRange("B6").clearContent();
formSS.getRange("C6").clearContent();
formSS.getRange("D6").clearContent();
formSS.getRange("E6").clearContent();
formSS.getRange("F6").clearContent();
formSS.getRange("G6").clearContent();
formSS.getRange("H6").clearContent();
formSS.getRange("I6").clearContent();
formSS.getRange("J6").clearContent();
return row[RETURN_COL_IDX];
}
}
}
}
//====================================================================
function updateData() {
var SPREADSHEET_NAME = "Data";
var SEARCH_COL_IDX = 0;
var RETURN_COL_IDX = 0;
var ss = SpreadsheetApp.getActiveSpreadsheet();
var formSS = ss.getSheetByName("Tool"); //Form Sheet
var datasheet = ss.getSheetByName("Data"); //Data Sheet
var str = formSS.getRange("A6").getValue();
var values = ss.getSheetByName(SPREADSHEET_NAME).getDataRange().getValues();
for (var i = 0; i < values.length; i++) {
var row = values[i];
if (row[SEARCH_COL_IDX] == str) {
var INT_R = i+1
formSS.getRange("J6").setValue(new Date())
var values1 = [[formSS.getRange("A6").getValue(),
formSS.getRange("B6").getValue(),
formSS.getRange("C6").getValue(),
formSS.getRange("D6").getValue(),
formSS.getRange("E6").getValue(),
formSS.getRange("F6").getValue(),
formSS.getRange("G6").getValue(),
formSS.getRange("H6").getValue(),
formSS.getRange("I6").getValue(),
formSS.getRange("J6").getValue()]];
var values2 = [[formSS.getRange("A6").getValue(),
formSS.getRange("B6").getValue(),
formSS.getRange("C6").getValue(),
formSS.getRange("D6").getValue(),
formSS.getRange("E6").getValue(),
formSS.getRange("F6").getValue(),
formSS.getRange("G6").getValue(),
formSS.getRange("I6").getValue(),
formSS.getRange("J6").getValue()]];
values2[0].forEach(function(val) {
if (val === "") {
throw new Error("Please fill in Revisions, Project, Category, Subsystem, Description and Updated By Fields.");
}
})
datasheet.getRange(INT_R, 1, 1, 10).setValues(values1);
formSS.getRange("A6").clearContent();
formSS.getRange("B6").clearContent();
formSS.getRange("C6").clearContent();
formSS.getRange("D6").clearContent();
formSS.getRange("E6").clearContent();
formSS.getRange("F6").clearContent();
formSS.getRange("G6").clearContent();
formSS.getRange("H6").clearContent();
formSS.getRange("I6").clearContent();
formSS.getRange("J6").clearContent();
formSS.getRange("E4").clearContent();
SpreadsheetApp.getUi().alert(' Record Updated ');
return row[RETURN_COL_IDX];
}
}
}
There are several posts about this, I'll paste a response from one from yesterday. What I recommend specifically in your case is to run the script when there's an edit bye the user in a certain cell. For example a Tickbox, or a Drop-down menu (in a cell) that allows the user to select which function to run:
If you already have an onEdit function working, that's a simple trigger run by whoever is editing the sheet. Meaning that if you protect column A, it won't be editable by that simple trigger because the user won't have permissions
In order to work this out, I encourage you to protect your column as explained here, change your name function or extract in a new function the part about this specific code you're talking about; and set an installable trigger that runs on event. This way it'll be run as you used to but as it came from your own account. As you have permissions for editing ColA the timestamp will be set by the installable trigger but the other user won't be able to edit it since he/she doesn't have the permissions. Try it and let me know!

Error after running apps script by trigger

I have code below. I've created trigger for this function. Type of trigger by minutes - every 15 minutes. "A" cell is a number that should be copy to G column by trigger. When it runs as result I see #ERROR. I need help with this
Maybe this #ERROR shows after running Delete function? And something wrong with this function?
function hourChart() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("PvD (auto)");
var value = sheet.getRange("A1").getValue();
var range = sheet.getRange("G1:G").getValues();
var lastRow = null;
var i = 0;
while(i < range.length) {
if (range[i][0] !== "") {
i++
} else {
lastRow = i +1;
break;
}
}
sheet.getRange(`G${lastRow}`).setValue(value)
}
function hourChartDelete() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("PvD (auto)");
var range = sheet.getRange("G2:G");
range.clear();
}
Please look to file

apps script - search value from sheet1 in array in sheet2 (google sheets)

I'm completely new to apps script and java.
I have a tracker where users insert IDs in col1 sheet1. I need to be able to prevent and alert them whenever their input DOESN'T exists in an array in col2 sheet 2.
so far I've got this, but this is not working for me at all.
var ss = SpreadsheetApp.getActiveSpreadsheet();
function onEdit(e) {
var sheet = ss.getSheetByName("Sheet1")
var so = ss.getSheetByName("Sheet2"); so.activate();
var vltest = sheet.getActiveCell().getValue()
var vlary = so.getActiveCell().getValue()
var r = sheet.getActiveRange().getRow()
var c = sheet.getActiveRange().getColumn();
if(vltest!=="" && c==1 && r>1 && sheet == "Sheet1"){
var data = so.getRange("B1:B").getValues().filter(String).flat()
if(data.indexOf(vlary)=data.lastIndexOf(vlary)){
e.range.setValue("")}
if(data.indexOf(vlary)=data.lastIndexOf(vlary)){SpreadsheetApp.getUi().alert("Alert", "Alert", SpreadsheetApp.getUi().ButtonSet.OK);}}}
Any ideas?
You need to get all values from compare sheet, loop them through and look for match of the value, that onEdit() gives you back. Something like this:
function onEdit(e) {
var ss = SpreadsheetApp.openById('sheet_ID'); //or getActive();
var so = ss.getSheetByName("Sheet2");
// let's say you get all rows from column 1
var compareData = so.getRange(1, 1, so.getLastRow(), 1).getValues();
for (var d = 0; d < compareData.length; d++) {
if (compareData[d] === e.value) {
SpreadsheetApp.getUi().alert("Alert", "Alert", SpreadsheetApp.getUi().ButtonSet.OK)
}
}

Add calendar event with the help of checkbox

With reference to this question - Not able to create event on Calendar with this script
The Code after all changes:
function onOpen() {
SpreadsheetApp.getUi().createMenu('⇩ M E N U ⇩')
.addItem('👉 Set up ...', 'myTriggerSetup')
.addToUi();
}
function myTriggerSetup() {
var ssID = SpreadsheetApp.getActiveSpreadsheet().getId()
if (!isTrigger('onSpeEdit')) {
ScriptApp.newTrigger('onSpeEdit').forSpreadsheet(ssID).onEdit().create();
}
}
function isTrigger(funcName) {
var r = false;
if (funcName) {
var allTriggers = ScriptApp.getProjectTriggers();
var allHandlers = [];
for (var i = 0; i < allTriggers.length; i++) {
allHandlers.push(allTriggers[i].getHandlerFunction());
}
if (allHandlers.indexOf(funcName) > -1) {
r = true;
}
}
return r;
}
function onSpeEdit(e) {
var rg = e.range;
if (rg.getRow() == 57 && rg.isChecked() && rg.getSheet().getName() === "Course") {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Course');
var start = new Date(spreadsheet.getRange('U70').getValue()).getTime();
var end = new Date(spreadsheet.getRange('X69').getValue()).getTime();
var name = spreadsheet.getRange('U69').getValue()
var calend = CalendarApp.getDefaultCalendar();
calend.createEvent(name, new Date(start), new Date(end));
rg.uncheck();
}
}
My Requirement:
A user will fill all 3 cells for event details. Then, they will tick on checkbox and the event should get added and also checkbox should get untick. Then, another user will do the same process again.
My Issues:
It is working in the dummy sheet but not in main sheet.My above code is as per main sheet.
Dummy Sheet: https://docs.google.com/spreadsheets/d/1_f_dujqIvmkXXLAqyandEmrWOxgskIfk9KTSKw28UuA/edit#gid=0
Thank you:
Thank you, Mike and Tanaike for the amazing efforts to help me.
Try this
function onOpen() {
SpreadsheetApp.getUi().createMenu('⇩ M E N U ⇩')
.addItem('👉 Set up ...', 'myTriggerSetup')
.addToUi();
}
function myTriggerSetup() {
var ssID = SpreadsheetApp.getActiveSpreadsheet().getId()
if (!isTrigger('onSpeEdit')) {
ScriptApp.newTrigger('onSpeEdit').forSpreadsheet(ssID).onEdit().create();
}
}
function isTrigger(funcName) {
var r = false;
if (funcName) {
var allTriggers = ScriptApp.getProjectTriggers();
var allHandlers = [];
for (var i = 0; i < allTriggers.length; i++) {
allHandlers.push(allTriggers[i].getHandlerFunction());
}
if (allHandlers.indexOf(funcName) > -1) {
r = true;
}
}
return r;
}
function onSpeEdit(e) {
var rg = e.range;
if (rg.getRow() == 4 && rg.isChecked() && rg.getSheet().getName() === "Course") {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Course');
var start = new Date(rg.offset(-2,0).getValue()).getTime();
var end = new Date(rg.offset(-1,0).getValue()).getTime();
var name = rg.offset(-3,0).getValue();
var calend = CalendarApp.getDefaultCalendar();
calend.createEvent(name, new Date(start), new Date(end));
rg.uncheck();
}
}
1. Rename your function name as follows.
In this case, you can also use the other function names except for onEdit. About the reason of this, you can see it at this thread.
function installedOnEdit(e){
var rg = e.range;
if(rg.getA1Notation() === "Z56" && rg.isChecked() && rg.getSheet().getName() === "Course"){
calendar(); //calling calendar function
rg.uncheck()
SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Course').getRange('X57').setValue('Event has been added to your Calendar')//Putting message in cell x57;
}
}
2. Install the installable OnEdit trigger to the renamed function.
You can see how to manually install this at the official document.
If you are required to use a script, you can also the following script.
function installTrigger() {
const ss = SpreadsheetApp.getActiveSpreadsheet()
ScriptApp.newTrigger("installedOnEdit").forSpreadsheet(ss).onEdit().create();
}
By this flow, installedOnEdit is run by the installable OnEdit trigger. When you use this, please check the checkbox. By this, installedOnEdit is run and CalendarApp.getDefaultCalendar() is run.
Note:
In this case, it supposes that your calendar() and the if statement in onEdit works fine. Please be careful this.
Reference:
Installable Triggers
Added:
I saw your provided sample Spreadsheet. When I saw it, the values of "Name", "Start Date", "End Date", "Add to Calendar" are the cells "B1:B4". But in your script, those values are not used. I think that your new issue is due to this. Please modify your script using your sample Spreadsheet as follows.
Modified script:
function calendar() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Course');
var start = new Date(spreadsheet.getRange('B2').getValue()).getTime();
var end = new Date(spreadsheet.getRange('B3').getValue()).getTime();
var name = spreadsheet.getRange('B1').getValue()
var calend = CalendarApp.getDefaultCalendar();
calend.createEvent(name, new Date(start), new Date(end));
}
function installedOnEdit(e) {
var rg = e.range;
if (rg.getA1Notation() === "B4" && rg.isChecked() && rg.getSheet().getName() === "Course") {
calendar(); //calling calendar function
rg.uncheck();
}
}
function installTrigger() {
const ss = SpreadsheetApp.getActiveSpreadsheet()
ScriptApp.newTrigger("installedOnEdit").forSpreadsheet(ss).onEdit().create();
}
In this case, when the installable OnEdit trigger is installed by installTrigger(), when the checkbox of cell "B4" is checked, the event is created.

Google Script: When cell is filled, have prompt ask if user wants to run script

I have written a script to clean up and move data between 3 different sheets. A user first paste a data extract on to the "Extract" page, and then runs the script.
When a user paste the data into cell A1 on the "Extract" page, I would like a prompt box to ask the user if they would like to run the script; if Yes, run script, if No, don't run script and show message. How would I go about doing this?
This is what I have so far...everything after the first function works.
function onEdit(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName("Extract");
if(ss.s().getRange("A1").getValue() != ""){
var ui = SpreadsheetApp.getUi()
var response = ui.alert('Would you jbot to find new claims for you?', ui.ButtonSet.OK_CANCEL);
if (response == ui.Button.OK) {
jbot();
} else {
Logger.log('The user clicked "No" or the close button in the dialog\'s title bar.');
}
}
}
function jbot(){
movetobot();
deleteRows();
removeDupesInOtherSheets();
deleteCol();
cleanup();
movetoqueue();
message();
};
function movetobot() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName("Extract");
var ts = ss.getSheetByName("bot");
s.getRange("A1:BW").moveTo(ts.getRange("A1"));
}
function deleteRows() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName("bot");
var r = s.getRange("BO:BO");
var v = r.getValues();
for(var i=v.length-1;i>=0;i--)
if(v[0,i]=='#POSTLESSEE' || v[0,i]=='#TDI CRC_OANKURA' || v[0,i]=='#Partpaymentoffer' || v[0,i]=='#TDI_CRC_DVANKURA' || v[0,i]=='#partpaymentdupe' )
s.deleteRow(i+1);
}
function removeDupesInOtherSheets() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s1 = ss.getSheetByName("bot").getDataRange().getValues();
var s2 = ss.getSheetByName("Queue").getDataRange().getValues();
// iterate 'Queue' and check in 'bot' if duplicate values exist
var nS1 = [];
var s2Col1 = [];// data in column1 of Queue
for(var n in s2){
s2Col1.push(s2[n][0]);
}
for(var n in s1){ // iterate '180418970' and test col 1 vs col 1 in 'Queue'
var noDup1 = checkForDup(s1[n],s2Col1)
if(noDup1){nS1.push(noDup1)};// if not present in 'Queue' then keep
}
Logger.log(nS1);// view result
ss.getSheetByName("bot").getDataRange().clear();// clear and update sheets
ss.getSheetByName("bot").getRange(1,1,nS1.length,nS1[0].length).setValues(nS1);
}
function checkForDup(item,s){
Logger.log(s+' = '+item[0]+' ?')
if(s.indexOf(item[0])>-1){
return null;
}
return item;
}
function deleteCol() {
var spread = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spread.getSheetByName("bot");
var lastCol = sheet.getLastColumn();
var keep = [1,2,3,4,45,53,74, 75]; // array of column numbers to keep
for (var col=lastCol; col > 0; col--) {
if (keep.indexOf(col) == -1) {
// This isn't a keeper, delete it
sheet.deleteColumn(col);
}
}
}
function cleanup() {
var spread = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spread.getSheetByName("bot");
sheet.getRange("B1:B").moveTo(sheet.getRange("H1"));
sheet.deleteColumn(2)
sheet.deleteRow(1)
var cell = sheet.getRange("D:D");
cell.setNumberFormat("m/d/yy");
var cell = sheet.getRange("F:F");
cell.setNumberFormat("m/d/yy");
var cell = sheet.getRange("A:A");
cell.setHorizontalAlignment("center");
var cell = sheet.getRange("C:D");
cell.setHorizontalAlignment("center");
var cell = sheet.getRange("F:G");
cell.setHorizontalAlignment("center");
sheet.autoResizeColumn(2)
sheet.autoResizeColumn(5)
sheet.autoResizeColumn(7)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spread.getSheetByName("bot");
var cell = sheet.getRange("BW1");
cell.setFormula("=COUNT(A:A)");
var spread = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spread.getSheetByName("bot");
var range = sheet.getRange("A1:G");
range.sort({column: 4, ascending: true})
}
function movetoqueue() {
var spread = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spread.getSheetByName("bot");
// skip row 1 (header) and beyond column G
var range = sheet.getRange(1,1,sheet.getLastRow()-1,7);
sheet = spread.getSheetByName("Queue");
var rows = sheet.getRange(1,1,sheet.getLastRow(),1).getValues();
// search for first blank row column 1
for( var i=0; i<rows.length; i++ ) {
if( rows[i][0] === "" ) {
var offset = sheet.getRange(1,1).offset(i,0);
range.copyTo(offset);
break;
}
}
}
function message() {
SpreadsheetApp.getActive().getSheetByName("Queue").activate();
var spread = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spread.getSheetByName("bot");
var range = sheet.getRange("bot!BW1:BW1");
var data = range.getValue();
Browser.msgBox(data + " new claims have been added to the queue. Thank you for using jBot!");
}
Your onEdit(e) will trigger the alert regardless of which cell is edited. You need to check the event range to limit it to cell A1 of Extract like this.
function onEdit(e) {
if( e.range.getSheet().getName() === "Extract" ) {
if( e.range.getA1Notation() === "A1" ) {
if( e.value !== "" ) {
var ui = SpreadsheetApp.getUi();
// Do the rest of your stuff here
}
}
}
}