i need some help from someone who is more experience than me.
I've the following formula
=WENNFEHLER(SVERWEIS($B$3;$B6:C;{2};0))
and the following script
function copyIntoCell() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('C3').activate();
spreadsheet.getRange('A3').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
};
How is it possible to add the formula into the script and also make it "onEdit" when a name entered into B3 it should auto insert the number into C3 from B6:C when B3 match with the database.
Also is it possible to autocomplete when I enter a word into B3 it suggest me the names from the database with the word I tipped in? This one is not important but would be nice.
Here is the example
Thanks for any help and idea I can get to complete what I looking for.
Combine script and formula as following:
Check if the edit was performed in column B
Retrieve the active row
setFormula() to assign your formula to the active row in column C
If the entered name is not found in the database and the formula returns the error "#NAME?" - delete the formula again
function onEdit(e) {
//check if edit takes place in the second column (B)
if(e.range.getA1Notation() =="B3"){
//proceed
var spreadsheet = SpreadsheetApp.getActive();
var row = e.range.getRow();
var formula = "=IFERROR(VLOOKUP($B$3,$B6:C,{2},0))";
//set formula to active row in column C
var cell = spreadsheet.getActiveSheet().getRange(row, 3);
cell.setFormula(formula);
}
};
Related
I have two vertical 1D arrays, one with existing data, and another that could (potentially) have differences.
I want to be able to compare the two arrays, find the differences AND the index of each cell that is different.
Then, I would use that information to find the appropriate cells in the existing data that need to be changed, and set the new values in those specific cells, without having to copy and paste the entire array.
For example:
Existing Data
New Data
John Smith
John Smith
012345
012345
6th grade
7th grade
555-1234
555-1357
Trumpet
Trumpet
5th period
2nd period
Jane Smith
Jane Smith
js#email.com
js#email.com
In this case, the code would see that rows 3,4, and 6 have differences, save those new values and their places in the array, then update the appropriate values in the main data list without changing anything else.
I've tried multiple ways to compare the two arrays AND get the index of the rows that have differences and this is as far as I've gotten without an error or a 'null' result:
function updateInfo() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var currentSheet = ss.getSheetByName("CURRENT");
var infoSheet = ss.getSheetByName("INFO Search");
var origVal = infoSheet.getRange(5,2,52,1).getValues();
var newVal = infoSheet.getRange(5,4,52,1).getValues();
var list = [];
var origData = origVal.map(function(row,index){
return [row[0],index];
});
Logger.log(origData);
var newData = newVal.map(function(row,index){
return [row[0],index];
});
Logger.log(newData);
This just gives me the value and index of each cell.
Is there a fast and efficient way to compare the two arrays, get the data I need, and change the values in just certain cells of the original column?
I can't just copy and paste the whole column over because there are formulas embedded in various rows that need to remain intact.
Thanks for any help you can provide!
Solution:
Iterate through the new data array. For each value, check whether the new value matches the old one. If that's the case, add the corresponding value and index to your list.
Then iterate through your list, and for each pair of value and index, write the value to the corresponding cell.
Code snippet:
newVal.forEach(function(row, index) {
if (row[0] === origVal[index][0]) {
list.push([row[0], index]);
}
});
var firstRow = 2; // Change according to your preferences
var columnIndex = 1; // Change according to your preferences
list.forEach(data => {
sheet.getRange(data[1] + firstRow, columnIndex).setValue(data[0]);
});
Notes:
I don't know where should the data be written, so I'm using undefined sheet, and also random values for firstRow and columnIndex. Please change these according to your preferences.
It would be much more efficient, from a script perspective, to write the whole column to your destination range at once, since that would minimize the number of interactions between the script and the spreadsheet (see Use batch operations). Since you want to write only the updated data, though, I provided a script that does this.
I have been searching the internet for hours! I have been working on an array index formula to search for multiple criteria and return multiple matches based on criteria in drop-down menu's. So, I have the following formula in cell E9 which searches cells E2,F2,G2,H2,I2 & J2 in the 'Summary' worksheet against their corresponding columns on the 'Main' worksheet.
=IFERROR(INDEX(Main!$E$3:$E$200,SMALL(IF(1=((--($E$2=Main!$A$2:$A$200))*(--($F$2<=Main!$C$2:$C$200))*(--($G$2>=Main!$D$2:$D$200))*(--($H$2=Main!$B$2:$B$200))*(--($I$2=Main!$H$2:$H$200))*(--($J$2=Main!$I$2:$I$200))),ROW(Main!$E$3:$E$200)-3,""),ROW()-8)),"")
Other formulas I have for SUMIF & COUNTIF allow the "*" to be selected in any of the drop-down lists to bypass that list, or 'select-all'. Is it possible to add something to the array formula to bypass that criterion if I want to 'select all'?
For example, in the images I've added Example 1 shows the Summary tab and Example 2 shows the Main tab. So, for the criteria I've chosen, what i want is to see a list in E9 downwards of all the journeys that 'Bob' has been on.
I would appreciate any advice.
Thanks very much.
You will need to put IFs inside for each criteria:
If($E$2 = "Select All",1,$E$2=Main!$A$2:$A$200)
so:
=IFERROR(INDEX(Main!$E$2:$E$200,
SMALL(
IF(If($E$2 = "Select All",1,$E$2=Main!$A$2:$A$200)*
If($F$2 = "Select All",1,$F$2<=Main!$C$2:$C$200)*
If($G$2 = "Select All",1,$G$2>=Main!$D$2:$D$200)*
If($H$2 = "Select All",1,$H$2=Main!$B$2:$B$200)*
If($I$2 = "Select All",1,$I$2=Main!$H$2:$H$200)*
If($J$2 = "Select All",1,$J$2=Main!$I$2:$I$200)
,ROW(Main!$E$2:$E$200)-1,"")
,ROW()-8)
),"")
I have a spreadsheet named Project log where I have 6 columns,
Timestamp Task Owner Date Keywords Email
Here we have different owners. I need to create a document with the owner name and move particular owner row to that owner document.
I am able to do this by looping but I had a issue when I get duplicate names it is creating another document and sending data but as per my requirement I need to have only one document on that particular owner and move duplicate owner name to owner itself.
Example of owner column.
joe
john
john
Here I need to create a document with "joe" name and append body with that whole row but I have two "john"s I need to create only one document i.e., "john" and move two rows to single document if I find more on his name I should be able to send that row to that particular owner document.
And my looping code is:
function createDocFromSheet() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.setActiveSheet(ss.getSheets()[2]);
var numRows=ss.getLastRow();
var values = ss.getDataRange().getValues()
for(n=2;n<=values.length;++n) {
var cell = sheet.getRange(n,3).getValue();
var row = sheet.getRange(n,2,1,5).getValues();
var newDoc = DocumentApp.create("Task Report - "+cell);
var body = newDoc.getBody();
body.insertParagraph(0,row);
newDoc.saveAndClose();
}
}
If the name is repeating in the column for just once, you can get the firstIndex and lastIndex of the range array and check if those two positions matches or not.
Giving an algorithmic code below:
var array1 = sheet.getRange(1,3,sheets.getLastRow()).getValues();
(Example values might be like array1 = [a,b,c,a,c,d])
var var1 = sheet.getRange(n,3).getValue();
var var2 = array1.indexOf(var1);
var var3 = array1.lastIndexOf(var1);
if(var2 == var3) {
// this means there is no repetition of the name.
}
else{
//get the values for both rows and create a document.
// Make a flag variable array to note that a doc is created with this name.
}
Hope that helps!
rookie coder here. I'm working in Google Scripts for a project and here's what I'm trying to do.
Essentially, I am trying to access a specific spreadsheet (called "Top Sheet") through an AICP address that has been entered in cell K2 of my "2013" spreadsheet. The Information that I am accessing in the "Top Sheet" spreadsheet is a single number located in cell K46. Then, I am taking the value of cell K46 (located in "Top Sheet") and placing it into a new cell (N2) in the "2013" spreadsheet.
Here's what that looks like (and it works).
function GetJobActuals() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s2 =SpreadsheetApp.openById(ss.getSheetByName("2013").getRange("K2:K2").getValue());
var v2 = s2.getSheetByName("Top Sheet").getRange("K46:K46").getValue();
ss.getSheetByName("2013").getRange("N2:N2").setValue(v2);
var s3 = SpreadsheetApp.openById(ss.getSheetByName("2013").getRange("K3:K3").getValue());
var v3 = s3.getSheetByName("Top Sheet").getRange("K46:K46").getValue();
ss.getSheetByName("2013").getRange("N3:N3").setValue(v3);
What I'm trying to do now, it make this happen for all of the preceding cells in the "2013" spreadsheet. For example, this code works for one number. Cell K2 in "2013" tells it to retrieve the value of cell K46 in "Top Sheet" and then returns with that value and places it into a new cell, N2.
How would I loop this so that this process would happen for the cell range of K2 - K60 and the repopulate the new cell range of N2 - N60?
Man I hope this makes sense, any and all help is appreciated. And again, the above code works, just trying to make a loop that can handle more than one thing at a time.
The answer should become clear to you if you use Sheet.getRange(row,column) instead of Sheet.getRange(a1Notation). By using row and column numbers instead of A1 notation, you can apply a for loop to acheive your goal.
ss.getSheetByName("2013").getRange("N3:N3").setValue(v3);
becomes
ss.getSheetByName("2013").getRange(3,14).setValue(v3);
^^^^
Row = 3, Column = 14 ("N")
So you can then iterate over rows:
for ( row=2; row<=60; row++) {
...
var s3 = SpreadsheetApp.openById(ss.getSheetByName("2013").getRange(row,11).getValue());
...
ss.getSheetByName("2013").getRange(row,14).setValue(v3);
...
}
Details left to you, but that's the basic structure for your loop. There are more efficient ways to make this work, but since you're new to this, worry about that after you get the basics working.
I have spreadsheet, want to get(Read) one cell data, through following link, I can able to add row, edit row, delete row, list of spreadsheets etc.. I can able to get all row information but i want to read only single cell data data, any one can give me syntax for that
I am using Python and Google App Engine
http://code.google.com/apis/spreadsheets/docs/1.0/developers_guide_python.html#AuthClientLogin
Thanks in advance
Kalyan
You didn't read far enough in the docs.
Modified ever so slightly from the linked example:
query = gdata.spreadsheet.service.CellQuery()
query['min-col'] = '1'
query['max-col'] = '1'
query['min-row'] = '2'
query['max-row'] = '2'
feed = gd_client.GetCellsFeed(key, wksht_id, query=query)
retrieves the data in the cell in column 1, row 2.