Google Sheets API querying - can you query multiple sheets at once? - api

I'm looking to create a searchable database from a Google Spreadsheet.
I've looked into what the API can do and I know you can query a sheet according to the gid ID. What I want to know is whether it is possible to query (so return matching search data) across the whole of a spreadsheet which has multiple sheets (and therefore multiple gids)?

Assuming your data is in Sheet1 and Sheet2 and the id is in column A (of both sheets), in Sheet3 enter the id to search for in A1 and the following in cell B1:
=query({Sheet1!A2:D;Sheet2!A2:D},"Select Col2,Col3,Col4 where Col1 <>'' AND Col1 = '" &A1&"'")

Related

Google Sheets Query() Function Returning Unexpected Data

I am having trouble with the QUERY() function in Google Sheets. I'm not certain I am using the correct function to generate the required data. I am far more comfortable with T-SQL, but my wife needs a mailing list generated from her current google sheets.
The facts:
Sheet2 is populated with data from B3:K150
I have a list of names in Sheet2, Column B.
I have a list of addresses in Sheet2, Column G
Sheet1 contains no data other than the data populated in Column B (See below)
Sheet1, Column B is populated with a unique list of names from
Sheet2, Column B using =Unique('Sheet2'!$B$3:$B$150).
Goal:
I would like to populate Sheet1, Column C with Sheet2, Column G
WHERE Sheet1(ColumnB) = Sheet2(ColumnB)
Obviously, using SQL, we would write this as such:
SELECT [Sheet1].[ColumnB]
,[Sheet1].[ColumnC]
FROM [Sheet1]
INNER JOIN [Sheet2]
ON [Sheet1].[ColumnB] = [Sheet2].[ColumnB]
What I have tried:
INSERT the following formula into Sheet1!C3:
=QUERY(Sheet2!B3:K150,"SELECT G WHERE B ='"&Sheet1!B3:B150&"'",0)
Sheet screenshots:
What am I missing?
This worked well for me:
=unique(query(Sheet2!B3:G150,"select B,G"))
as posted by user: pnuts in comments above.
Try this in Sheet1C3 =Arrayformula(if(B3:B=Sheet2!B3:B,Sheet2!G3:G,"")) Let me know if you need me to explain the formula.

Excel Autofilter, Copy selection, Paste to new sheet

I have a table with source data in columns Regions!A6:R553.
In Regions!A3:R3, I have formulas that pull specific information out of my data table in Regions!A6:R553 that I want copied to a different sheet.
Column A acts as my project name column, while column B holds ID numbers. In my case, there are multiple ID numbers per project.
I am looking for a script to filter and loop through all the unique order numbers in Column B one by one, then copy cells A3:R3 to RegionsSummary!A12:R12 for as many rows as there are unique order numbers (i.e, add rows to the table).
Here is a screengrab of my data sheet, "Regions":
i.stack.imgur.com/aTPuw.png
Here is a screengrab of the empty template sheet "RegionsSummary":
i.stack.imgur.com/9Ukz5.png
Example: Assume there are 5 projects in my data sheet. I will filter the data using another macro to select Project_1. I would then like a command button to active a macro that will filter to the first order number in Column B, copy Regions!A3:R3 to RegionsSummary!A12:R12, then filter to the second order number in Project_1, and repeat the process. This should go on until all unique ID numbers have been filtered and looped through.
Here is a screengrab of what a final product should look like:
i.stack.imgur.com/9Ukz5.png
Here is a link to the file: Final Output Example
I would go with an easier solution than a Macro with certain constraints. I am not able to access your sheet, so I will make a sample excel.
STEPS:
Create a list of unique projects for a dropdown (COPY Regions!A5:A10000 to a new sheet > Data > Remove Duplicates) . Create the dropdown (Data Validation > List > Select Range) using Data Validation in "Example_Result" sheet- C7.
In "Regions", in Col S, put the below formula
=S6&"_"&COUNTIF($S$6:S6,S6)
Copy this formula down for the entire sheet or as long as you expect the sheet to grow
In "Example_Result", insert an index column (1 to 1000, in Col A if you expect each project to have 1000 or less order numbers) from A12 onwards.
Along the columns (B onwards) of Row 11 include the names of the variables from Regions (Assessment Project, Highway etc).
Insert the below formula in B12 to S1000 (depending on number of variables) of Example_Result:
=IFERROR(INDEX(Regions!$A$5:$S$10000,MATCH($C$7&"_"&A$12,Regions!$S$5:$S$10000,0),MATCH(B$11,Regions!$A$5:$H$5,0)),"")

How to Auto Fill Cells in Excel based on a dependent drop down list?

I have 2 sheets in sheet1 is the master sheet where all data are stored
In sheet2 I want to link the data of sheet1 in sheet2 in different cells
In Sheet1 I have 'Name' 'Mobile' 'Address' 'Pin' in A1 B1 C1 D1
In Sheet2 A2 I did data validation of the name of the persons which is stored in Sheet1, now I want that when I will select the respect list automatically the Mobile Address Pin of the person will auto fill in B2 C2 D2
& for that I am using the following formula
=VLOOKUP($A2,Sheet1!$A:B,COLUMNS(Sheet1!$A:B),0)
If a person having 3 mobile numbers stored in my Sheet1, I want to place those 3 mobile numbers in my Sheet2 Mobile column, How do I do that ??
Column A is the main dependent, But if there are blank rows then Data validation doesn't work, how can I do that ??
or any macro required ??
This is a tricky one. You will need to have a unique identifier in your records somewhere because a VLOOK and a MATCH formula will only pull back the first record it finds.
I would suggest looking into this link, it tells you how to do this. I have done it before, but it takes some practice no doubt so be warned.
Excel to the Next Level by Mastering Multiple Occurrences

Copy rows with a specific value to another sheet

I have a huge Excel worksheet which contains 200,000 rows. The data is about 120 subjects which are listed in column B, like sinani-01 to sinani-120. I need to copy all rows where column B contains sinani-01, for example, and paste them to new sheet. Or at least just select them?
Can you please let me know how to do this in VBA?
Excel has an AutoFilter function that you can use to select only the rows that contain a specific value. You use it like this:
' Filter column B by a specific value...
Range("B:B").AutoFilter 1, "sinani-01"
' Copy all visible rows to a new sheet...
Range("B:B").SpecialCells(xlCellTypeVisible).EntireRow.Copy Sheets("sinani-01").Range("A1")
' Turn the AutoFilter back off...
Range("B1").AutoFilter

vlookup if name is matched display employee id

Ive never used vlookups i have a spreedsheet not sure if this is the right function. I have two sheets
Sheet 1
first name last name username
Sheet 2
first name last name employee id business unit
I need in column D on sheet 1 to have employee id ive below. Pay no attention to column letters and sheets because i moved to another sheet to try getting this right.
=MATCH(B11,Sheet1!C:C,0)
Any help is much appreciated.
So you realize you have to match both first and last names? There are several ways to accomplish this depending on how many employees you have in sheet 2: a) small list could a two-column search using array formula; b) large list just create another column in both sheets joining last & first names and do a MATCH or VLOOKUP on them.
Since your needs are simple and to illustrate option (b):
Insert a column in both Sheet1 and Sheet2 after the "last name"; you should now have an empty column C in both sheets.
Assuming you have column headers in row one, and thus data starts in row two, set cell C2 in both sheets with function =B2&","&A2, then fill-down that formula on both sheets in all rows.
Set Sheet1 cell E2 to formula =VLOOKUP(Sheet1!C2, Sheet2!$C:$D, 2, False), and fill-down that formula in all rows.
Voila, employee IDs on Sheet1. I do have to say this is so Excel 101. There are all sorts of examples and tutorials on this easily found using even the most trivial Google searches.