I'm trying to get data to appear based on a drop down and a secondary column. Here's the sample sheet: https://docs.google.com/spreadsheets/d/1LgHrze7bp0Epfw273Ylx3sVW98VDyd0sSQ1lYmZJUL4/edit?usp=sharing
I'm trying to get the Data sheet info to appear under the dropdown in the Worksheet sheet.
Any help would be great! Thanks!
Use hlookup like this. Put in B2 of Worksheet:
=transpose(arrayformula(hlookup(B1,Data!B1:G8,{2,3,4,5,6,7,8},false)))
If you put the cities in the rows, it would be much easier for you to add new cities. You can set the dropdown data validation to A2:A and the lookup to A2:H.
You can then add cities without adjusting anything. The formula the uses vlookup like:
=transpose(ARRAYFORMULA(vlookup(A1,RData!A2:H,{2,3,4,5,6,7,8},false)))
You can also do it with Google Apps Script that will expand to the number of cities and categories you have. I have added this to the shared sheet on the Script tab. It uses the RData tab as its source.
function onEdit(event) {
var sheet = event.source.getActiveSheet().getName()//get the sheet name
if(sheet=="Script" ){//if sheet name is Script
var ss= SpreadsheetApp.getActiveSpreadsheet()
var s=ss.getSheetByName("RData")//get the data sheet
var lr=s.getLastRow()//get the last row with data(city)
var lc=s.getLastColumn()//get the last column with data (category)
var rng=s.getRange(1, 1, lr, lc).getValues()//get the values
var dd= s.getRange("Script!A1").getValue()//get the selected city from the dropdown
var val=[]
var cat=[]
for(i=0;i<rng.length;i++){
if(dd==rng[i][0]){
for(j=1;j<rng.length+1;j++){
var t=rng[i][j]
val.push([rng[i][j]])
cat.push([rng[0][j]])
ss.getSheetByName("Script").getRange(1, 2, val.length,1).setValues(cat) //write the category values
ss.getSheetByName("Script").getRange(1, 3, val.length,1).setValues(val) //write the numbers
break //quit when the city is processed
}}}}}
Attached is a shared spreadsheet the shows all ways of solving your problem:
https://docs.google.com/spreadsheets/d/1h3kYpBTK8OpSVL5PGwQzYsFbIHmCaKx0G5Y8FXSdHH8/edit?usp=sharing
Related
I will try to be as clear as possible. Here is the example piece: link
What I want to happen is that the Filter formula will search for any Sheet containing “Form Responses” and then display the results. You can see on the Current sheet how I’ve been doing, but this is more tedious and leads to issues of the first formula begins to overwrite the next one, etc. On the Wanted tab, I’ve laid out how I imagine it and put a note in A7. Any help offered is greatly appreciated!
You can get started with this script:
function getSheetResponses(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Wanted");
var getCellValue = sheet.getRange("A7").getValue(); //Gets the name of your designated sheet on "Wanted Sheet" cell "A7"
var getName = ss.getSheetByName(getCellValue);
var getNameValue = getName.getRange(2,5,getName.getLastRow(),1).getValues(); //Gets all the values of Column E on any defined sheet names based on getCellValue
var datalength = getNameValue.length;
Logger.log(datalength);
sheet.getRange(8,6,datalength,1).setValues(getNameValue); //Puts the data on Wanted Sheet Column F
}
What this does is it gets the sheet name on cell A7, and populates the data on Column F row 8 on the "Wanted" sheet like so:
Now, the data it populates on the "Wanted" sheet came from Form Responses 1 based on the sample piece you have provided:
If ever you would want to relocate which specific row or column the data would be pasted on "Wanted" Sheet. You can refer to this documentation on how to modify the rows and columns on sheet.getRange()
Reference:
https://developers.google.com/apps-script/reference/spreadsheet/sheet#getrangerow,-column,-numrows,-numcolumns
Hello i'm using google sheet as my second databse and in the main page called Companies i have a list of companies as shown below:
and i wrote a function that generate a new tab for every companie in the first column. here is what a tab looks like
my goal is in the companies tab under "Workers" i want to get the value of "Total workers" of each companie. the list of companies will be constantly growing so i thought about maybe a function that uses the value of the first column to search for the tab and then get the value of G2.
I am really new to google sheet and i would appreciate any help on how to solve this problem
SUGGESTION
You can try this sample script below with custom function named getTotalWorkers & then add it as a bound script to your Spreadsheet file:
UPDATED Script:
function getTotalWorkers(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var names = ss.getRange("Company!A2:A").getValues().filter(String); //get names of the sheets on column A
var res = [];
for(x=0; x<names.length; x++){
var data = ss.getRange(names[x]+"!G2").getValue(); //get the current cell G2 values on every sheet tabs
res.push([data]); //place all values to a tem[orayr array variable
}
ss.getSheetByName("Company").getRange(2,6,res.length,1).setValues(res); //add the values under the "Workers" column on Company sheet tab
}
Sample Demonstration
After saving the script from the Apps Script editor, place the updated getTotalWorkers function to a time-driven trigger:
The time driven trigger will auto populate the "Workers" F column cells every minute (based on my sample time-driven trigger configuration):
I have a range of data populated from a google form in sheet "Data".
I need to make a report (in sheet "Report") that shows the students attendance, based on name (from drop down list). The data that is blank is excluded in that report, as seen in column i to column k
desired result
I have shared the sheet here
I have tried to use filter
=filter(Data!B1:I20,Data!E1:E20<>"")
but still I cant find the way to change the "condition" in this formula to refer to the sheet Report A1.
what is the correct formula to achieve this?
Thanks you for your help.
Using Apps Script you will have to use the function getSheetByName(name).
Example:
// The code below logs the index of a sheet named "Expenses"
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Expenses");
if (sheet != null) {
Logger.log(sheet.getIndex());
}
Then to find from column E the rows that have value you would have to use the getRange(a1Notation) method:
// Get a range A1:D4 on sheet titled "Invoices"
var ss = SpreadsheetApp.getActiveSpreadsheet();
var range = ss.getRange("Invoices!A1:D4");
// Get cell A1 on the first sheet
var sheet = ss.getSheets()[0];
var cell = sheet.getRange("A1");
Then you would have to iterate over that rows and get the rows where the E column has something.
Once you have that you can get the Report sheet and set the values there with setValues(values)
For more information on how the function you may need to use you have the reference of SpreadsheetApp and the overview on Extending Google Sheets
I'm new to this,
I have 2 google spreadsheets:
Spreadsheet A: The active sheet Containing multiple tabs with information to be Pushed to B.
Spreadsheet B: A spreadsheet with a single tab. The same headers and structure as spreadsheet A.
Based on the user selecting the answer "Yes" in the first column of any of the 1 tabs in Spreadsheet A, I would like that entire row to move over to Spreadsheet B.
I have modified a script that works on a single spreadsheet (ie moving rows from tab to tab) to attempt to get it to work between spreadsheets:
function onEdit(event) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var tss = SpreadsheetApp.openById('B').getSheetByName('Sheet 1');
var s = event.source.getActiveSheet();
var r = event.source.getActiveRange();
if(r.getColumn() == 1 && r.getValue() == "Yes") {
var row = r.getRow();
var numColumns = s.getLastColumn();
var target = tss.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).moveTo(target);
}
}
Probably needless to say, this yields no result. Having searched through a number of posts and forums I only see individuals posting about how to move rows between tabs but not between entirely separate spreadsheets. Is it even possible to do this? If so, what am I doing wrong in the script?
Thank you so much for anyone who takes the time to assist.
Anthony
Following a dialogue with the OP in the comments section, it was indicated that the original spreadsheet did not to be kept secret.
Consequently, the desired functionality can be provided by using a combination of IMPORTRANGE() and QUERY() in the spreadsheet with no need to use Google App Script. For instance,
=QUERY(IMPORTRANGE(url,range),"select A where B matches 'Yes'") or similar
This imports data from a second spreadsheet and then the QUERY() function acts as a way of filtering the imported range by certain criteria.
Once the imported range is authorised, the editors of the spreadsheet can access it by, e.g. removing or modifying the query. You could prevent this by protecting that particular cell, if needed.
I have very limited knowledge of google sheets and would appreciate any and all help.
I have created a google sheet with multiple sheets. I would like to have the names that are typed in the cells for student names name the following sheets.
Thank you.
Here is a link to the google sheet: https://docs.google.com/spreadsheets/d/1pOOwg5HLGXVg9XynJBGcVWjqnCV6xZSmMX38hZZgmvg/edit?usp=sharing
How about following script?
function sample() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var summarysheet = ss.getSheetByName('Put name of summary sheet name');
var names = summarysheet.getRange('a4:a38').getValues();
names.forEach(function(e, i){
ss.getSheets()[i + 1].setName(e);
});
}
I thought that it is very important the correspondence of names of summary sheet and each sheet. So conditions to use this sample script is as follows.
If you change the arrangement of sheets, the correspondence of names of summary sheet and each sheet cannot be done.
How do you think about the correspondence of names of summary sheet and number of sheets? Now, the number of sheets is 35 + (a summary sheet). This is same to (names of summary sheet) + 1. If you want to insert new sheets using script, please tell me.
It cannot make sheets with same sheet name. So if there are same student names, it is necessary to change a bit.
If you have a script you made for your question, can I ask you about it?