I'm trying to make a script in google sheets that make this:
I have a database with "id" and "product" in the sheet named "base":
In another sheet I have the "id2" and the "product2":
I need to create a Script that search (vlookup I think) the "id2" in the first database and bring 'yes' or 'no' according to the product2 and put it on the obs column
This logic can be expressed by double application of filter: first, filter the columns of Sheet1 so that the column you get is the one with product name in it (B2 in your example); then filter the rows so you get the Id as in the cell A2.
=filter(filter(Sheet1!A2:D, Sheet1!A1:D1 = B2), Sheet1!A2:A = A2)
Related
I'm working with google Sheets and I have a sheet call source Sheet where names are listed in Column A
ColumnA
John
Peter
etc
In a separate sheet (target sheet), i import this list'names (column A) and associate other information regarding each person.
Like this :
in cell A2 of Target sheet, i put this formula
=importrange("ID sheet";"source Sheet!A2:A")
So i get the same list which is what i wanted. To that list, i associated a couple of additional information regarding to each of them like
*Target Sheet*
Column A = names Column B = Age Column C = Occupation etc
When i remove a person in the source sheet, the target sheet is updated but the information which was associated to that person stays in the target sheet.
What can i do to remove automatically the info asoociated to a person (target sheet) once i remove someone from the Source sheet ?
Background
I am making a Database of organiser names, which i want to update with a Google Form.
I already made a Form which feeds a Spreadsheet "Form Responses" sheet with the organiser details: Continent, Country and Chapter/City. The Database is already existing with current organisers, split into continent specific sheets, so i need to add new organisers from the form to this database. If a new organiser is from a new country/chapter, that needs to be added to the database as well.
Question
What formula can I use to feed the "Form Responses" sheet rows into the "Database" sheets, without having multiple rows of the same Country and Chapter? That is, add the "Organiser" column to an existing "Country" + "Chapter", or add the new "Country" + "Chapter" + "Organiser" to the bottom of the correct "Continent_Database".
Maybe the only way to do this might be to add all new rows from the "Form Responses" sheet to the bottom of the correct "Continent_Database", and merge the rows in the case of already existing Country + Chapter, in an additional sheet.
Example
Spreadsheet example with some test Form Responses and a "Africa_Database" example sheet:
https://docs.google.com/spreadsheets/d/1QaDNQp-HrbueQchmlXGSr7cFZ9r2x7ml148vSJL4Q0w/edit?usp=sharing
You could be looking to use a query here. In the case below 'A2' points a cell containing a country name. Transpose will convert a downward list to a horizontal and the query will get all names from column G where column C contains that the country in cell 'A2'
=transpose(QUERY('Form Respones'!B:G,"SELECT G WHERE C ='"&A2&"'",0))
Here is an example
In my Google spreadsheet, in column H I have a list of IP numbers. What I need to a script what will take those numbers and fetch the Country name. I need this to be script since the spreadsheet gets populated from a web-form. What I have is a formula that does that perfectly but I have to copy the formula manually with each form submission. Since I get lots of submissions per day, it's tedious to do this manually. I need the script to run on spreadsheet update. The formula I have is this:
=query( importhtml("http://whatismyipaddress.com/ip/" & H1526, "table", 2), "select Col2 where Col1 = 'Country:' ", 0 )
The last populated row is H1526. I tried the "ARRAYFORMULA" but no array formulas seems to work with my query function. The column where I have the IPs is H and I need the country name in column I.
You can write script on submit of the Google form. Also you need to set a trigger for the same. Hope this helps.
function OnSubmit(e){
var sheetDatabase = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
sheetDatabase.getRange(sheetDatabase.getLastRow(), 8).setFormula('=query(importhtml("http://whatismyipaddress.com/ip/"&I'+sheetDatabase.getLastRow()+', "table", 2), "select Col2 where Col1 = \'Country:\' ", 0 )');
}
I use a Google SpreadSheet add-on to make Google Analytics Reports. My problem is that for each query this add-on creates a different sheet. I often have around 50 different sheet with data that must be compiled into a single sheet. For example:
I might have 3 sheets named: "Organic Data", "Direct Data" and "Other Data"
Each sheet has a different set of data that I want to compile into a single table in a 4th sheet called "Report". This table will have in its first column data from the "Organic Data" sheet, in its second column data from the "Direct Data" sheet and in its third column data from the "Other Data" sheet.
The way I´m doing this is by referencing the cells one by one. So in the "Report" sheet I will write =Organic Data!B4 and then drag to fill the other cells of the column, and then I would do this for the other sheets to fill up the other columns of the "Report" sheet.
The problem is that, as I´ve said, I often have more than 50 different sheets and referencing them can get quite hard.
I would like to do this dynamically. Have the names of the sheets on a cell and use that to reference the cells. For example:
In the "Report" sheet:
A1 = "Organic Data", B1 = "Direct Data", C1 = "Other Data"
In cell "Report!A2" I´ve tried writing =CONCAT("=",A1,"!","B4") hoping to get in this cell the value of the cell "Organic Data!B4", but instead I get the string "=Organic Data!B4, and not the value of the cell in "Organic Data" sheet.
I`ve made a custom formula to solve this problem:
function referenceSheet(sheetName, cellInput) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var cell = ""
var cell = sheetName+'!'+cellInput;
var value = ss.getRange(cell).getValue();
return value;
}
It works quite well. In my example above to get the value of the cell "Organic Data!B4" into the cell "Report!A2", I need to write on "Report!A2" the following:
"=referenceSheet(A1, cell("address",B4))"
and it will return the value of the cell "Organic Data!B4".
I do have some issues with this custom formula that I´ve made. Mainly, custom formulas don´t refresh onChange, so if I change the value of "Organic Data!B4", "Report!A2" will not change.
I would like to know if there´s a native formula that does something similar to my custom formula?
If not, what´s the best way to make my custom formula to refresh as I change the date from other cells?
Thank You Very Much!
I´ve posted the same question on Google Forums and got a nice answer.
There is a native formula call =INDIRECT
For my exemple it works like this:
=INDIRECT(CONCATENATE(A$1,"!",cell("address",$B4)),true)
I am creating a calendaring/scheduling resource. The user inputs all calendaring/event data in a Google Form. Each time a form is submitted, the data populates to a "Form Responses" spreadsheet, where a new row is created. From within the spreadsheet, the spreadsheet owner can run a script to create Google Calendar entries.
Among the data collected through the Google Form, the user can choose from among 100+ calendars upon which he would like his event information to appear. So, for example, he can choose from among calendar names such as "Apple", "Pear", "Watermelon", and "Orange" from a list of over 100 calendars. In the spreadsheet, these selections would appears in a comma-separated list: apple, pear, watermelon, orange.
In a separate "resource" spreadsheet, I have two columns. Column 1 contains the above calendar names, and Column 2 contains the corresponding Google Calendar resource address.
COL A
A1 Apple
A2 Pear
A3 Watermelon
A4 Orange
COL B
B1 domain.com_190382d0931#resource.calendar.google.com
B2 domain.com_928313sdf98#resource.calendar.google.com
B3 domain.com_239829a3l18#resource.calendar.google.com
B4 domain.com_295801a0181#resource.calendar.google.com
I need a script that reads the user-submitted calendar name data in the "Form Responses" spreadsheet, searches the "Resources" Spreadsheet for the same data, and returns the substituted Google Calendar resource addresses in a comma-separated value in a designated column in the "Form Responses" spreadsheet.
Example:
User 1 submits data that he wants to book his event on Calendars "Pear" and "Apple"
User 2 submits data that he wants to book his event on Calendars "Orange" and "Apple"
User 3 submits data that he wants to book his event on Calendars "Pear", "Apple", and "Orange"
In "Form Responses" spreadsheet, three rows of data are created. One column contains the calendar data for each submission.
So:
J2 contains Pear, Apple
J3 contains Orange, Apple
J4 contains Pear, Apple, Orange
I want a column at the end of the Form Responses spreadsheet to populate with the resource equivalents, as pulled from the "Resource" spreadsheet.
So:
Z2 contains domain.com_928313sdf98#resource.calendar.google.com, domain.com_190382d0931#resource.calendar.google.com
Z3 contains domain.com_295801a0181#resource.calendar.google.com, domain.com_190382d0931#resource.calendar.google.com
Z4 contains domain.com_928313sdf98#resource.calendar.google.com, domain.com_190382d0931#resource.calendar.google.com,
domain.com_295801a0181#resource.calendar.google.com
This is very simple to manage with arrays.
take you cell with comma separated values and split it on commas (which is the default split element). For example : var calNamestoWrite = cell.split(','); and you'll get an array of n elements
read you second sheet using getValues() so that you get a 2D array of as much elements as rows in sheet2.
For example : var calNames = ss.sheet2.getDataRange().getValues();
Then in a double for loop you can simply check the calendar names by comparing
if(calNamestoWrite[n]==calNames[c][0]){ var calID = calNames[c][1] ... and do the other stuf...}
since the first column was the name and the second was the calendar ressource id.
n iterates the calNamestoWrite array and c iterates the array from sheet2.
et voilà, this would take you a couple of minutes to write.