search columns in different spreadsheets - google-apps-script

Okay, I will try to explain in words what Im trying to accomplish, hoping that someone will be able push me in the right direction.
I have two different google spreadsheets:
One named ”Ads_sent_in” containing a couple of different columns that is automatically filled in by a PHP file on my website.. (its a list of file uploads that is being uploaded through a web-form). These are clients that uploads adverts (pdf’s) that are to be put in a magazine for print.
One of the columns in ”Ads_sent_in” is called ”Ordernumber” and contains a specific, unique number for the advert.
the other spreadsheet named ”Magazine_name_03-2019”. This is where all the adverts a placed on the different pages in the magazine, all in one spreadsheet. Each advert is represented by 1 row and 3 columns of info/data.
They are: Advertisers name/client name - advert size - ordernumber (Same number as in the other spreadsheet above in point 1.
Now,
I want do make a script that will be able to search the ”Ads_sent_in” spreadsheet for the ”ordernumber”, and find the same ”ordernumber” in the other spreadsheet ”Magazine_name_03-2019”.
If there is a match, the textcolor of ”ordernumber” (and also if possible, the cell which is always located one step/column to the left of where ”ordernumber” is) should be changed to green.
If no match, do nothing.
Is this possible?
=============================
EDIT
I pick up the ordernumber from the Ads_sent_in sheet using this bit of code:
var ordernumber = sheet_Ads.getRange(sheet_Ads.getLastRow(), 1).getValues();
After that I think all I need is a function that will search the Magazine_name_03-2019 sheet for the ordernumber I get from above..
The best scenario would be if that function could search a whole spreadsheet (both columns and rows) for the ordernumber and return the cell (for example 'D5'). I don't need any values returned, I just need to know where this ordernumber is located, in what cell in the Magazine_name_03-2019 sheet.
Then store the cell location (for example 'D5') in:
var ordernumber_loc = sheet_Magazine_name_0319.getActiveCell ?
I'd like to back off two columns to the left of the ordernumber_loc above if possible and store it in another variable
var client_cell_loc = ordernumber_loc - "2 columns"
From there on I want to change the color of client_cell_loc text to green and make it bold:
var style = SpreadsheetApp.newTextStyle()
.setForegroundColor("green")
.setBold(true)
.build();
range.setTextStyle(style);
(Sorry if its a bit messy, I dont know much about coding.. but want to learn :)

This is possible. Steps could be as follows -
Input ordernumber using a prompt
Search in Ads_sent_in
Search in Magazine_name_03-2019
If match, color cell/row

Related

Copy Adjacent Cells alongside Duplicate Cells

I have a very large Google Sheet spreadsheet that I need help with.
I have a long list of Network Switches that are very often repeated that I am trying to automatically copy the associated SKU into a separate adjacent cell.
My goal was, once the SKU is added the first time, whenever the same switch is added again, it will autopopulate with the same SKU.
For instance, C2461:C2463 are repeated, and once K2461 is populated, would like K2462 & K2463 to follow suit.
Any help would be greatly appreciated!
You can try this formula on Column L (col L will serve as a helper column):
=iferror(arrayformula(VLOOKUP(C2:C,C2:K,9,False)),"")
For now I can't seem to fit the formula without the use of a helper column (so I created a separate sheet for now that will serve as a database for the VLOOKUP formula) but this should get you started.
Sample using a helper spreadsheet (Database):
=iferror(arrayformula(VLOOKUP(Database!A2:A,Database!A2:B,2,False)),"")
Output:

How to send cell data from one google spreadsheet to another, but only if the cell colour is correct?

I have a spreadsheet with cells coloured in two different colours. I know I can send all the cell data from one google spreadsheet to another using IMPORTRANGE function. However, I only want to send the cell data if it satisfies a specified cell colour.
For example, if spreadsheet A has 10x10 data with various colours, then spreadsheet B should contain all the data from cells in spreadsheet A that are either red or green (and also transfer the cell colours). All other cells with different colours from spreadsheet A should be transferred to spreadsheet B as blank colourless cells. The resulting spreadsheet should still contain 10x10 cell data, but with only red, green and blank cells.
I know it should be possible to write a function for this, but I have never written any custom functions before and have no Javascript experience. Any kind of help would be appreciated. Perhaps also the QUERY function could be of use?
Thanks in advance!
You should check about Google Apps Script. It gives you a set of tools that will allow you to create a script for doing what you want.
Custom Functions will help you to create a function that lets you get the values from your sheet and then set the conditions you are requiring.
The Class SpreadsheetApp has the tools for handling all data in your sheets. Check for example the method getBackgrounds(), which gets the color in a range of cells.
This another post, it is a little similar in some aspects to what you want to do.
It's best practice to create an additional column which stores the information regarding as to which condition (color) is applied 5o the particular row. Once you have done that, you can easily transport a table from one Spreadsheet to another using the QUERY formula within the IMPORTRANGE.
Image column a is the name of a city.
Imagine column b holds the information regarding the condition (color). This is an helper column.
Now we have col1 = New York City, col2= green
Then you could enter this into the new sheet.
QUERY( IMPORTRANGE(URL, range), "SELECT col1 WHERE col2="green" OR col2="yellow" OR col2="red")
Here is a great tutorial series I like to use.
https://youtu.be/_N5zhAipVn0

How to Programatically Access Google Spreadsheet File Name

Question is simple. How to get Name (File name in Google Drive) of a spreadsheet using spreadsheet identifier. If you want to know why I need it, you may please continue reading further.
I have created two type of spreadsheets to manage my financial books with my friends, family and business.
Type 1: A book that contains all transactions with a specific person and tells Amount owed or amount lended. I have about 15 of such sheets. Check this screenshot:
Type 2: A sheet named as investments. It fetches data from all other sheets using Sheet Identifier and displays total amount invested or borrowed. Check this screenshot:
In Type 2 sheet, I have programmed and made everything automated. You just need to paste Identifier of any new Spreadsheet in G Column and you're done. Only one thing is Killing me. I am unable to fetch name of the spreadsheet using Identifier. I fetched all records of the sheet using IMPORTRANGE Method, just the file name is not getting fetched. I tried plenty of functions.
Yellow Columns denotes Automatic Columns. I just want to make Column B automatic in case of Type 2 Spreadsheet. It should contain Spreadsheet File Name fetched through Sheet Identifier, same as I fetched all rows of multiple sheets & made calculations within Type 2 sheet. Thanks for considering to help me out.
If I understood your question correctly, you want the name of a Sheets file from the Sheets ID? How about:
var spreadsheetId = 'YOUR_SPREADSHEET_ID';
var sheetName = SpreadsheetApp.openById(spreadsheetId).getName();

Copying values from Google sheet, add time stamp, prevent duplicates

I'm using Kimono to scrape a site that lists active development permits. For a one off data scrape it's fine, the problem is that there is no way of sorting new data. Every time Kimono scrapes it updates the entire array.
This is what the sheet currently looks like
https://docs.google.com/spreadsheets/d/1BH8ESAHQJrog6x8nRBOpgBN-nTN1_aDY7wr8W_YYet0/edit#gid=1865015934
The first sheet is automatically populated and overwritten by Kimono. It seems like the most logical way of making this work would be to copy the values to another sheet, adding a time stamp when this happens and then preventing duplicate values from being posted.
Following this thread is was able to muster this code
I've got the copying part down with the following:
function moveValuesOnly() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var source = ss.getRange('Building Permits!A1:D');
source.copyTo(ss.getRange('Sheet2!A1'), {contentsOnly: true});
source.clear();
}
What I am trying to figure out is how to prevent duplicates based on the URL value.
I know that it is right in front of me, but I'm drawing a blank on how to get this to work.
This Google documentation article on removing duplicates is very well written, so I won't duplicate it: https://developers.google.com/apps-script/articles/removing_duplicates
It has exactly what you need. Read the later part of the article where it talks about how to check duplicates not for the entire row, but specific columns in that row. Once you understand that, your problem is straightforward to solve. Just use 2 arrays, to hold the contents of the rows from the 2 sheets as in the example they've given. compare the first column value of the current row. if it matches, don't copy the row over.
note: this works only when you copy row-by-row into the target sheet, not the entire range as your'e doing right now. But that's unavoidable.

Keeping value after reference cell has been changed

I need cell B3 to reference B1 while blank.
Once you put something in B1 it'll keep that value forever, even once B1 get's changed to something else.
This is my situation:
Basically I have a sheet that is fed by a Google form and each submission needs three key reference numbers each kept in columns a,b,c
A = Unit Number/Individuals name (There may be duplicates down the sheet as this is per submission)
B = Work Order (Imputed by me after actual work on unit has been done)
C = Cry Number/Reference number (Automatically generated per submission; no duplicates)
I then have a frozen row at the top which contains a search bar that you can search for the cry number (A1)(Which has a Data Validation set to column C so that you can only search valid cry numbers) and then a cell to add a W/O to that Cry Number (B1)
In column B3:1000, I have this formula copied down:
B3=if(isblank($C3),"",if($A$1=$C3, SUBSTITUTE($B$1,"",$B$1),""))
...which makes it so that if you select say "CN-168" (A valid cry number) and in 'B1' type "W1134" that work order number will be assigned.
Now I need that work order to stay there regardless of when 'A1' changes so that you can do the process over again on another submission.
Is it possible to do with formulas? If not, then a Google Script?
Here is a template of what I'm dealing with but not to the same scale as my Data Base
Its not possible with formulas but easily done with apps script. look at the onEdit trigger and the documentation for SpreadsheetApp to setValues to the appropiate ranges.
If you want to be 100% complete you also need a time trigger (say every 10 minutes) to check that a row wasnt missed. It can be missed during apps script errors/outages or when the sheet is changed from outside the sheets webpage/app (For example using the http spreadsheet api)