I have a dropdown list that is in my workbook in the first tab (Tab titled: Reference Don't Edit) and I have a schedule template (aptly titled "Schedule Template").
I am trying to make the dropdown lists on all of the subsequent tabs (which would be daily tabs) instead of creating a new workbook everyday. I tried changing the dropSS and dropSS_ from using a sheet name to SpreadsheetApp.getActiveSpreadsheet().getSheets() and .getSheet(), etc for use on all active sheets, but it just erases the working dropdown and doesn't put it on the other sheets.
function createPrimaryDrpdwon() {
var dataSS = "References *Don't Edit*";
var dropSS = "Schedule Template";
var primaryDataRange = "A1:A46";
var primaryDropRange = "H4:H";
var primaryDropList = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(dataSS).getRange(primaryDataRange).getValues();
var primaryDropRange = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(primaryDropRange);
var validationRule = SpreadsheetApp.newDataValidation().requireValueInList(primaryDropList).build();
primaryDropRange.setDataValidation(validationRule);
}
function createSecondaryDrpdwon(e){
var dataSS = "References *Don't Edit*";
var dropSS = "Schedule Template";
var dropSS_ = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(dropSS);
var allDataRange = "A1:B46";
var primaryDDCol = 8;
var dropDData = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(dataSS).getRange(allDataRange).getValues();
var activeCell = dropSS_.getActiveCell();
var activeColumn = activeCell.getColumn();
var activeRow = activeCell.getRow();
if(activeColumn==primaryDDCol){
var dep_Col = primaryDDCol+1;
var dep_Row = activeRow;
var depCell = dropSS_.getRange(dep_Row, dep_Col);
var primarySelected = activeCell.getValue();
var validationRule = SpreadsheetApp.newDataValidation().requireValueInList(getDependentList(dropDData,primarySelected)).build();
depCell.setDataValidation(validationRule);
}
}
function getDependentList(dropDData,primarySelected){
var dependenList = [];
var j = 0;
if(dropDData != null){
for(i=0; i<dropDData.length; i++){
if(dropDData[i][0]==primarySelected){
dependenList[j] = dropDData[i][1];
j++;
}
}
}
return dependenList;
}
Try this:
function createPrimaryDrpdwon() {
var dataSS = "References *Don't Edit*";
var dropSS = "Schedule Template";
var primaryDataRange = "A1:A46";
var primaryDropRange = "H4:H";
const ss = SpreadsheetApp.getActive();
var primaryDropList = ss.getSheetByName(dataSS).getRange(primaryDataRange).getValues().map(r => r[0]).filter(e => e);
var primaryDropRange = ss.getActiveSheet().getRange(primaryDropRange);
var validationRule = SpreadsheetApp.newDataValidation().requireValueInList(primaryDropList).build();
primaryDropRange.setDataValidation(validationRule);
}
function getDependentList(dropDData, primarySelected) {
var dependenList = dropDData.map(r => {
if (r[0] == primarySelected) {
return r[1];
} else {
return '';
}
}).filter(e => e);
return dependenList;
}
Related
I am trying to count the number of colored cells in one range that meet the condition "Active" in another range. If the cell doesn't match the criteria ('light gray 3' in ranges $T9:$BL9 and "Active" in the range $T$2:$BL$2) then it must not be counted. How can I edit the current script to adjust for this?
function countColoredCells(countRange,colorRef) {
var activeRange = SpreadsheetApp.getActiveRange();
var activeSheet = activeRange.getSheet();
var formula = activeRange.getFormula();
var rangeA1Notation = formula.match(/\((.*)\,/).pop();
var range = activeSheet.getRange(rangeA1Notation);
var bg = range.getBackgrounds();
var values = range.getValues();
var colorCellA1Notation = formula.match(/\,(.*)\)/).pop();
var colorCell = activeSheet.getRange(colorCellA1Notation);
var color = colorCell.getBackground();
var count = 0;
for(var i=0;i<bg.length;i++)
for(var j=0;j<bg[0].length;j++)
if( bg[i][j] == color )
count=count+1;
return count;
};
Try this:
function countColoredCells(countRange,colorRef) {
const ss = SpreadsheetApp.getActive();
var activeRange = SpreadsheetApp.getActiveRange();
var activeSheet = activeRange.getSheet();
var formula = activeRange.getFormula();
var rangeA1Notation = formula.match(/\((.*)\,/).pop();
var range = activeSheet.getRange(rangeA1Notation);
var bg = range.getBackgrounds();
var colorCellA1Notation = formula.match(/\,(.*)\)/).pop();
var colorCell = activeSheet.getRange(colorCellA1Notation);
var color = colorCell.getBackground();
var count = 0;
bg.forEach((r,i) => {
r.forEach((c,j) => {
if(c == color) {
count++;
}
})
})
return count;
};
I tried to put together a script which would create calendar events only for the check marked rows in a spreadsheet, but if I had 3 rows checked, it would create 3 events based on the first checked row (so 3 same events).
Console log identifies the 3 different rows, but .createEvent takes the first checked row only, does not move onto the second and the third.
Here's the code, what have I messed up?
function createThickEvents() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("formhelper");
var data = sheet.getRange("A1").getDataRegion().getValues()
var approveData = data.filter(r => r[10] === true && r[11] === "")
var cal1 = "calendarID";
var cal2 = "calendarID";
var cal3 = "calendarID";
var cal4 = "calendarID"
var calendars = {
Name1: CalendarApp.getCalendarById(cal1),
Name2: CalendarApp.getCalendarById(cal2),
Name3: CalendarApp.getCalendarById(cal3),
Name4: CalendarApp.getCalendarById(cal4)}
approveData.forEach(r => {
var emailAddress = approveData[0][1];
var title = approveData[0][2];
var tstart = new Date(approveData[0][3]);
var tstop = new Date(approveData[0][4]);
var usingDays = approveData[0][6];
var remainingDays = approveData[0][9];
var desc = approveData[0][5];
var calComp = approveData[0][8];
var newEventComp = calendars[calComp].createEvent(title, tstart, tstop, {description:desc})
console.log(approveData)
})
}
I would do it like this:
function createThickEvents() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sh = ss.getSheetByName("formhelper");
const vs = sh.getRange("A1").getDataRegion().getValues();
const cal1 = "calendarID";
const cal2 = "calendarID";
const cal3 = "calendarID";
const cal4 = "calendarID"
const calendars = {
Name1: CalendarApp.getCalendarById(cal1),
Name2: CalendarApp.getCalendarById(cal2),
Name3: CalendarApp.getCalendarById(cal3),
Name4: CalendarApp.getCalendarById(cal4)
}
vs.forEach(r => {
if(r[10] === true && r[11] =="") {
let emailAddress = r[1];
let title = r[2];
let tstart = new Date(r[3]);
let tstop = new Date(r[4]);
let usingDays = r[6];
let remainingDays = r[9];
let desc = r[5];
let calComp = r[8];
calendars[calComp].createEvent(title, tstart, tstop, { description: desc })
}
})
}
Below is a script written by Jordan Rhea and provided via github.
I am trying to follow its logic so that I can understand how to approach automatically populating a form with questions that have conditional logic flowing to different sections of a Google Form.
The code is breaking at line 35 "ReferenceError: form is not defined (line 35, file "RosterMaker")
Line 35 = var classSection = form.addPageBreakItem().setTitle(className).setGoToPage(FormApp.PageNavigationType.SUBMIT);
I'm sure this is a simple error, but I cannot figure it out.
var ssID = "something";
var formID = "something"
//SpreadsheetApp.openById(ssID).getSheetByName("db_type");
function rosterMaker() {
//spreadsheet id of the rosters
var SHEET_ID = SpreadsheetApp.getActive();
var ss = SpreadsheetApp.openById(ssID);
var form = FormApp.openById((formID));
//get only the sheets with 'Roster' in the title
var sheets = ss.getSheets()
.filter(function(sheet) {return sheet.getName().match(/Roster/gi);});
//add multiple choice item
var classSelect = form.addMultipleChoiceItem()
.setTitle('Choose a class');
Logger.log(classSelect);
//get the class choices for the multiple choice item
var classChoices = getClasses(sheets);
//assign the choices to the classSelect variable
classSelect.setChoices(classChoices);
}
function getClasses(sheets) {
var classChoices = [];
for(var i = 0; i < sheets.length; i++) {
var className = sheets[i].getName();
var classSection = form.addPageBreakItem()
.setTitle(className)
.setGoToPage(FormApp.PageNavigationType.SUBMIT);
var students = getStudents(sheets[i]);
var studentSelect = form.addCheckboxItem()
.setTitle(className + ' absent')
.setHelpText('Select the students who are absent from this class');
var studentChoices = [];
for(var j = 0; j < students.length; j++) {
studentChoices.push(studentSelect.createChoice(students[j]));
}
studentSelect.setChoices(studentChoices);
classChoices.push(classSelect.createChoice(className, classSection));
}
return classChoices;
}
function getStudents(sheet) {
var studentValues = sheet.getDataRange().getValues();
var students = [];
for(var i = 1; i < studentValues.length; i++) {
students.push(studentValues[i].join(' '));
}
return students;
}
Test this:
var ssID = "something";
var formID = "something";
function rosterMaker() {
var SHEET_ID = SpreadsheetApp.getActive();
var ss = SpreadsheetApp.openById(ssID);
var form = FormApp.openById((formID));
var sheets = ss.getSheets().filter(function(sheet) {return sheet.getName().match(/Roster/gi);});
var classSelect = form.addMultipleChoiceItem().setTitle('Choose a class');
var classChoices = getClasses(sheets,form);//modified
classSelect.setChoices(classChoices);
}
function getClasses(sheets,form) {//modified
var classChoices = [];
for(var i = 0; i < sheets.length; i++) {
var className = sheets[i].getName();
var classSection = form.addPageBreakItem().setTitle(className).setGoToPage(FormApp.PageNavigationType.SUBMIT);
var students = getStudents(sheets[i]);
var studentSelect = form.addCheckboxItem().setTitle(className + ' absent').setHelpText('Select the students who are absent from this class');
var studentChoices = [];
for(var j = 0; j < students.length; j++) {
studentChoices.push(studentSelect.createChoice(students[j]));
}
studentSelect.setChoices(studentChoices);
classChoices.push(classSelect.createChoice(className, classSection));
}
return classChoices;
}
function getStudents(sheet) {
var studentValues = sheet.getDataRange().getValues();
var students = [];
for(var i = 1; i < studentValues.length; i++) {
students.push(studentValues[i].join(' '));
}
return students;
}
I haven't learned how to adjust so that if there is an error in the script when trying to capture data from openweathermat.org, the word ERROR is written in cell A10 on the Clima page of my spreadsheet.
I would like help and advice on how I should adjust the script to make this happen.
function TudoCompleto() {
var ss=SpreadsheetApp.getActive();
var sh=ss.getSheetByName('Clima');
var rg=sh.getRange("B12");
var vA=rg.getValues();
if (vA[0][0]=="OK"){
var spreadsheet = SpreadsheetApp.getActive();
var ss = SpreadsheetApp.getActive();
var sheet = ss.getSheetByName("Clima");
var apiKey = "XXXXXXXXXXXXXXXXXXXXXXXXX";
var cityName = sheet.getRange("A1").getValue();
var apiCall = "api.openweathermap.org/data/2.5/weather?q=" + cityName +"&appid=" + apiKey;
var response = UrlFetchApp.fetch(apiCall);
var data = JSON.parse(response.getContentText());
Logger.log(response.getContentText());
var weather = data["weather"][0]; //It's an array
var sys = data["sys"];
var main = data["main"]
var location = data["name"];
var country = sys["country"];
var weatherDesc = weather["main"];
var temp = main["temp"];
var minTemp = main["temp_min"];
var maxTemp = main["temp_max"];
var weatherData = [
["Location:", location],
["Country:", country],
["Weather:", weatherDesc],
["Teaperture:", temp],
["Min Temp:", minTemp],
["Max Temp:", maxTemp]
];
sheet.getRange(3, 1, weatherData.length, weatherData[0].length).setValues(weatherData);
//The API Call works
// The Data will be retrieved like below JSON file.
//{"coord":{"lon":139,"lat":35},
//"sys":{"country":"JP","sunrise":1369769524,"sunset":1369821049},
//"weather":[{"id":804,"main":"clouds","description":"overcast clouds","icon":"04n"}],
//"main":{"temp":289.5,"humidity":89,"pressure":1013,"temp_min":287.04,"temp_max":292.04},
//"wind":{"speed":7.31,"deg":187.002},
//"rain":{"3h":0},
//"clouds":{"all":92},
//"dt":1369824698,
//"id":1851632,
//"name":"Shuzenji",
//"cod":200}
var spreadsheet = SpreadsheetApp.getActive();
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); // planilha ativa
var sheet = spreadsheet.getSheetByName("Clima");
for (var i = 1; i < 2; i++) {
var cel = "F"+ i //
if (sheet.getRange(cel).getValue() != "") {
for (var u = 1; i < 2000; u++) {
var cel2 = "R"+ u //
if (sheet.getRange(cel2).getValue() == "") {
sheet.getRange("R"+u).setValue(sheet.getRange(cel).getValue());
break;
};
}
}
};
var spreadsheet = SpreadsheetApp.getActive();
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); // planilha ativa
var sheet = spreadsheet.getSheetByName("Clima");
for (var i = 1; i < 2; i++) {
var cel = "B"+ i //
if (sheet.getRange(cel).getValue() != "") {
for (var u = 1; i < 2000; u++) {
var cel2 = "S"+ u //
if (sheet.getRange(cel2).getValue() == "") {
sheet.getRange("S"+u).setValue(sheet.getRange(cel).getValue());
break;
};
}
}
};
var spreadsheet = SpreadsheetApp.getActive();
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); // planilha ativa
var sheet = spreadsheet.getSheetByName("Clima");
for (var i = 1; i < 10; i++) {
var cel = "H"+ i //
if (sheet.getRange(cel).getValue() != "") {
for (var u = 1; i < 2000; u++) {
var cel2 = "M"+ u //
if (sheet.getRange(cel2).getValue() == "") {
sheet.getRange("M"+u).setValue(sheet.getRange(cel).getValue());
break;
};
}
}
};
spreadsheet.getRange('Clima!A12').activate();
spreadsheet.getActiveRangeList().clear({contentsOnly: true, skipFilteredRows: true});
spreadsheet.getRange('Clima!R:S').activate();
spreadsheet.getRange('Clima!I:J').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
};
};
In order to publish, I had to add the entire script at the request of a member to help him understand my need. I apologize for the long script.
function TudoCompleto() {
var ss=SpreadsheetApp.getActive();
var sh=ss.getSheetByName('Clima');
var rg=sh.getRange("B12");
var vA=rg.getValues();
try{
if (vA[0][0]=="OK"){
var spreadsheet = SpreadsheetApp.getActive();
var ss = SpreadsheetApp.getActive();
var sheet = ss.getSheetByName("Clima");
var apiKey = "XXXXXXXXXXXXXXXXXXXXXXXXX";
var cityName = sheet.getRange("A1").getValue();
var apiCall = "api.openweathermap.org/data/2.5/weather?q=" + cityName +"&appid=" + apiKey;
var response = UrlFetchApp.fetch(apiCall);
var data = JSON.parse(response.getContentText());
Logger.log(response.getContentText());
var weather = data["weather"][0]; //It's an array
var sys = data["sys"];
var main = data["main"]
var location = data["name"];
var country = sys["country"];
var weatherDesc = weather["main"];
var temp = main["temp"];
var minTemp = main["temp_min"];
var maxTemp = main["temp_max"];
var weatherData = [
["Location:", location],
["Country:", country],
["Weather:", weatherDesc],
["Teaperture:", temp],
["Min Temp:", minTemp],
["Max Temp:", maxTemp]
];
sheet.getRange(3, 1, weatherData.length, weatherData[0].length).setValues(weatherData);
var spreadsheet = SpreadsheetApp.getActive();
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); // planilha ativa
var sheet = spreadsheet.getSheetByName("Clima");
for (var i = 1; i < 2; i++) {
var cel = "F"+ i //
if (sheet.getRange(cel).getValue() != "") {
for (var u = 1; i < 2000; u++) {
var cel2 = "R"+ u //
if (sheet.getRange(cel2).getValue() == "") {
sheet.getRange("R"+u).setValue(sheet.getRange(cel).getValue());
break;
}
}
}
}
var spreadsheet = SpreadsheetApp.getActive();
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); // planilha ativa
var sheet = spreadsheet.getSheetByName("Clima");
for (var i = 1; i < 2; i++) {
var cel = "B"+ i //
if (sheet.getRange(cel).getValue() != "") {
for (var u = 1; i < 2000; u++) {
var cel2 = "S"+ u //
if (sheet.getRange(cel2).getValue() == "") {
sheet.getRange("S"+u).setValue(sheet.getRange(cel).getValue());
break;
}
}
}
}
var spreadsheet = SpreadsheetApp.getActive();
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); // planilha ativa
var sheet = spreadsheet.getSheetByName("Clima");
for (var i = 1; i < 10; i++) {
var cel = "H"+ i //
if (sheet.getRange(cel).getValue() != "") {
for (var u = 1; i < 2000; u++) {
var cel2 = "M"+ u //
if (sheet.getRange(cel2).getValue() == "") {
sheet.getRange("M"+u).setValue(sheet.getRange(cel).getValue());
break;
}
}
}
}
spreadsheet.getRange('Clima!A12').activate();
spreadsheet.getActiveRangeList().clear({contentsOnly: true, skipFilteredRows: true});
spreadsheet.getRange('Clima!R:S').activate();
spreadsheet.getRange('Clima!I:J').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
}
}
catch(e) {
ss.getSheetByName("Clima").getRange('A10').setValue('ERROR');
Logger.log(e);
}
}
I have a google spreadsheet "shared" where it consists of all the bill of materials. I want to keep another spreadsheet "master" such that only owner can access that. Any data inserted in the shared spreadsheet should get reflected in master spreadsheet, but if we edit shared spreadsheet it should not get reflected in master spreadsheet.
Any help would be appreciated.
Well it depends on what you mean by "changes", but you could put =Master!A1 in cell A1 of the slave sheet, then drag the bottom right corner all the way down, then drag the bottom right corner of that selection all the way across. So cell D8 will have =Master!D8, and so on.
Google Spreadsheets does have a scripting capability. It also has a public gallery script.
image http://img593.imageshack.us/img593/5410/screenshot20110720at736.png
One of the public scripts is edit to another spreadsheet
edit to another spreadsheet
update in another spreadsheet the changes in the current one
ticcaje (at) gmail.com
image http://img97.imageshack.us/img97/240/picture1nns.png
unfortunately it has not been updated in some time, and after looking at the code I don't think it was ever actually completed, as there is a dialog message and then a return statement.
image http://img718.imageshack.us/img718/5264/pictureja.png
I think this could be a really useful script and so I've done a little editing with it, but actually there are no comments in it, and I don't have the time to get it working 100% right now, but I wanted to post it here in hopes that somebody could actually pick it up and run with it.
function onEdit(){
var sourceSpreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var targetSpreadsheet = SpreadsheetApp.openById('0AntUWac3dtkUac3dtnhTjMwac3dtVjBiac3dtOXcac3dt'); //put in your spreadsheet key here
var sourcesSheet = sourceSpreadsheet.getSheets()[0];
var targetSheet = targetSpreadsheet.getSheets()[0];
var currentSourceCellIndex = SpreadsheetApp.getActiveRange().getRow(); //ActiveCell().getValues();
var selectedCell = SpreadsheetApp.getActiveSpreadsheet().getActiveSelection().getA1Notation();
var targetRowsCount = targetSheet.getLastRow();
var targetColumns = sourcesSheet.getLastColumn();
var targetRange = targetSheet.getRange(1, 1, targetRowsCount, targetColumns);
var targetSources = targetRange.getValues();
var sourceRows = sourcesSheet.getLastRow();
var sourceColumns = sourcesSheet.getLastColumn();
var sourcesRange = sourcesSheet.getRange(1, 1, sourceRows, sourceColumns);
var sources = sourcesRange.getValues();
var compareName = sources[currentSourceCellIndex-1][0];
return;
//Browser.msgBox("currentSourceCell: "+sources[currentSourceCellIndex-1][0]);return; // ActiveCell()
//Browser.msgBox("currentSourceCell: "+targetRowsCount);
// return;
for (var i = 1; i < targetRowsCount; ++i) {
if (targetSources[i-1][0] == compareName){
targetSheet.deleteRow(i);
break;
}
}
// var sourceRows = sourcesSheet.getLastRow();
// var sourceColumns = sourcesSheet.getLastColumn();
// var sourcesRange = sourcesSheet.getRange(1, 1, sourceRows, sourceColumns);
// var sources = sourcesRange.getValues();
//if ((sources[sourceRows-1][0] == "")||(sources[sourceRows-1][1] == "") ||(sources[sourceRows-1][2] == "") || (sources[sourceRows-1][3] == "") || (sources[sourceRows-1][4] == "") || (sources[sourceRows-1][5] == ""))
//return;
//currentSourceCell = sourceSheet.getActiveCell();
rowToInsert = targetSheet.getLastRow();
targetSheet.insertRowAfter(rowToInsert);
var insertRange = targetSheet.getRange(rowToInsert + 1, 1, 1, targetSheet.getLastColumn());
var kolonnen = [];
var tbText = [];
for (var i = 1; i < 16; ++i) {
kolonnen.push(i);
tbText.push(sources[sourceRows-1][i-1]);
}
//Browser.msgBox("source is: "+tbText);return;
for (j = 0; j < kolonnen.length; j++) {
var zellRange = targetSheet.getRange(rowToInsert+1, kolonnen[j], 1, 1);
zellRange.setValue(tbText[j]);
}
}
The original code can be accessed by editing the script, but if you want it I'll just go ahead and post it here, too:
function onEdito() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [ {
name: "go",
functionName: "insertRow"
}
// ,
// {
// name: "Build Journal",
// functionName: "collectJournal"
// }
];
ss.addMenu("pastePlus", menuEntries);
}
function onEdit(){
var sourceSpreadsheetName = Browser.inputBox("source spreadsheet");
//var sourceSpreadsheetName = SpreadsheetApp.getActiveSpreadsheet().getName();
var files = DocsList.getFilesByType("spreadsheet");
//var files = SpreadsheetApp;
Browser.msgBox("currentSourceCell: " +files);
//var sourceSpreadsheet;
for (var i = 0; i < files.length; ++i) {
var filename = files[i].getName();
if (filename == sourceSpreadsheetName) {
var sourceSpreadsheet = SpreadsheetApp.openById(files[i].getId());
var sheets = sourceSpreadsheet.getSheets();
var sourcesSheet = sheets[1];
break;
}
}
var targetSpreadsheetName = "Probando Script"; //DocsList.getFilesByType("spreadsheet");
//var targetSpreadsheet;
for (var i = 0; i < files.length; ++i) {
var filename = files[i].getName();
if (filename == targetSpreadsheetName) {
var targetSpreadsheet = SpreadsheetApp.openById(files[i].getId());
var sheets = targetSpreadsheet.getSheets();
var targetSheet = sheets[1];
break;
}
}
var currentSourceCellIndex = SpreadsheetApp.getActiveRange().getRow(); //ActiveCell().getValues();
var selectedCell = SpreadsheetApp.getActiveSpreadsheet().getActiveSelection().getA1Notation();
var targetRowsCount = targetSheet.getLastRow();
var targetColumns = sourcesSheet.getLastColumn();
var targetRange = targetSheet.getRange(1, 1, targetRowsCount, targetColumns);
var targetSources = targetRange.getValues();
var sourceRows = sourcesSheet.getLastRow();
var sourceColumns = sourcesSheet.getLastColumn();
var sourcesRange = sourcesSheet.getRange(1, 1, sourceRows, sourceColumns);
var sources = sourcesRange.getValues();
var compareName = sources[currentSourceCellIndex-1][0];
//Browser.msgBox("currentSourceCell: "+sources[currentSourceCellIndex-1][0]);return;
Browser.msgBox("currentSourceCell: "+targetRowsCount);return;
for (var i = 1; i < targetRowsCount; ++i) {
if (targetSources[i-1][0] == compareName){
targetSheet.deleteRow(i);
break;
}
}
var sourceRows = sourcesSheet.getLastRow();
var sourceColumns = sourcesSheet.getLastColumn();
var sourcesRange = sourcesSheet.getRange(1, 1, sourceRows, sourceColumns);
var sources = sourcesRange.getValues();
//if ((sources[sourceRows-1][0] == "")||(sources[sourceRows-1][1] == "") ||(sources[sourceRows-1][2] == "") || (sources[sourceRows-1][3] == "") || (sources[sourceRows-1][4] == "") || (sources[sourceRows-1][5] == ""))
//return;
//currentSourceCell = sourceSheet.getActiveCell();
rowToInsert = targetSheet.getLastRow();
targetSheet.insertRowAfter(rowToInsert);
var insertRange = targetSheet.getRange(rowToInsert + 1, 1, 1, targetSheet.getLastColumn());
var kolonnen = [];
var tbText = [];
for (var i = 1; i < 16; ++i) {
kolonnen.push(i);
tbText.push(sources[sourceRows-1][i-1]);
}
//Browser.msgBox("source is: "+tbText);return;
for (j = 0; j < kolonnen.length; j++) {
var zellRange = targetSheet.getRange(rowToInsert+1, kolonnen[j], 1, 1);
zellRange.setValue(tbText[j]);
}
}