Google sheets: Record date when selecting particular drop down - google-sheets

Is it possible to capture the date, or be asked to enter a date when selecting a particular drop down value?
For example, if a task is complete, when selecting "complete" from a dropdown list, I want the date captured for record in a different cell.
Many thanks for your help!

We can add script in google sheet to track particular column activity.
function onEdit() {
var s = SpreadsheetApp.getActiveSheet();
if (s.getName() == "Sheet1") { //checks that we're on Sheet1 or not
var r = s.getActiveCell();
if (r.getColumn() == 1) { //checks that the cell being edited is in column A
var nextCell = r.offset(0, 1);
if (nextCell.getValue() === '') //checks if the adjacent cell is empty or not?
nextCell.setValue(new Date());
}
}
}
Refer:
Capture Time Stamp Demo

Related

How do I conditionally highlight dates within a start and end date range based on individual date rows?

so I have this workbook that I am trying to figure out how to manage in a more automated way.
I have 2 main sheets. In 'Sheet2' there are 4 columns (Item, Sub-Item, Start, End). In 'Sheet1' there is similar data just formatted differently. Each valid permutation of Item and Sub-Item is already listed and the dates are expanded. Under each permutation of item/subitem I want to be able to enter 'True' if the date is affected and have it highlight any matching affected rows in 'Sheet2'. To be a match it needs to match the Item and Sub-Item and have a highlighted date that falls within the date range (exclusive of the End date) in 'Sheet2'. It doesn't have to be done in google sheets, it could also be done in excel if that makes it any easier or different.
I've linked a sample sheet below. Hopefully that helps clear up any questions.
https://docs.google.com/spreadsheets/d/1Smsxr5_qsj0hLhc5oIJHsX-ISpB9p66vc1z4wOd3CNk/edit
Try this:
Here I created an onEdit Trigger that will execute a function whenever an edit in Sheet was made and used its property to determine the item, sub-item, and date. Then compare it to each row in Sheet2. I added comment to each line of code to explain the process.
Code:
function isInBetween(t, s, e){
let target = new Date(t); //convert target date to date format
let start = new Date(s); //convert start date to date format
let end = new Date(e); //convert end date to date format
if(target.getTime() >= start.getTime() && target.getTime() < end.getTime()){ // check if target date is in between of start and end -1
return true;
}else{
return false;
}
}
function onEdit(e) {
let spreadsheet = SpreadsheetApp.getActiveSpreadsheet()
let range = e.range; //get the range of edited cell
let sheet = range.getSheet() //get the sheet of edited cell
let row = range.getRow(); //get the row of edited cell
let column = range.getColumn(); //get the column of edited cell
if(row > 5 && column > 1 && column < 7 && sheet.getName() == 'Sheet1' && e.value == 'TRUE'){ //check whether the edited cell is in the editable range in sheet1
let sheetItem = sheet.getRange(1, column).getDisplayValue(); //get the corresponding item of the edited cell
let sheetSubItem = sheet.getRange(4, column).getDisplayValue(); //get the corresponding sub item of the edited cell
let dateToCheck = sheet.getRange(row, 1).getDisplayValue(); //get the date of edited cell
let sheet2 = spreadsheet.getSheetByName('Sheet2');
let data = sheet2.getRange(2, 1, sheet2.getLastRow()-1, 4).getDisplayValues(); //get all values in sheet2
data.forEach(function(row, i) { //iterate each values in sheet2
let sheet2Item = row[0]; //get the item in sheet2
let sheet2SubItem = row[1]; //get the sub item in sheet2
let start = row[2].replace(new RegExp('-', 'g'), '/'); //replace the '-' of start date with '/'
let end = row[3].replace(new RegExp('-', 'g'), '/'); //replace the '-' of end date with '/'
if(sheetItem == sheet2Item && sheetSubItem == sheet2SubItem && isInBetween(dateToCheck, start, end)){ // this will check if the item, subitem of sheet1 matches in sheet2, this will also check if the date is in between
sheet2.getRange(i+2, 1, 1, 4).setBackground("#b7e1cd"); //change the color of affected row in sheet2 to green
}
})
}
}
Demo:
References:
Simple Trigger
Google Apps Script
Event Object
Class Range
Class Sheet
Class Spreadsheet

Needed for the Date and Time return formula in Excel

This is the code to return time for getting the first message text in column C61.
=if(ISTEXT(C61),TEXT(NOW(),"hh:mm"),"00:00")
This is the code to return time for last message in column E61.
=if(ISTEXT(E61),TEXT(NOW(),"hh:mm"),"00:00")
This code works fine to return time, But when the last message is entered in column E61 the time at column B61 also gets changed. I don't understand why this is happening, because there is no relation of these two columns to each other. They have to change the times on column B61 and D61.
But they both are grabbing the same time from the system.
this is not possible to solve with formulae. you need a script:
function onEdit(e) {
var s = SpreadsheetApp.getActiveSheet();
if( s.getName() =="Sheet1" ) { //sheet
var r = s.getActiveCell();
if( r.getColumn() == 5 ) { //monitor column E
var nextCell = r.offset(0, -1); //print timestamp in column D
var newDate = Utilities.formatDate(new Date(),
"GMT+8", "HH:mm"); //format of the timestamp and timezone
nextCell.setValue(newDate);
}}}
https://stackoverflow.com/a/71815326/5632629

How to match a string above a given cell index

I have a schedule like this and somehow determined the position of Alice in B7.
Given the index B7, how can I find the matching date? Here it would the first cell above Alice that starts with October.
SUGGESTION
It looks it would be quite tricky to use just solely the pre-defined functions to achieve this, given that the total number of names per dates are random (some dates has only 2 names and other has 3 based on your sample sheet).
You can try using a custom formula for this method, just copy and paste the sample functions below as a bound script to your sheet file then adjust it your setup:
function FINDDATE(cell) {
var sheet;
if(cell.split("!").length==1){
sheet = SpreadsheetApp.getActive().getActiveSheet();
}else{
sheet = SpreadsheetApp.getActive().getSheetByName(cell.split("!")[0]);
}
var selectedLoc = sheet.getRange(cell);
for(i=selectedLoc.getRow(); i != 1; i--){
var dateFound = isValidDate(sheet.getRange(i,selectedLoc.getColumn()).getValue());
if(dateFound == true){ //Return the date of the very first detected as date above the index
var res = Utilities.formatDate(sheet.getRange(i,selectedLoc.getColumn()).getValue(), Session.getScriptTimeZone(), "MMMM d");
return res.toString();
}
}
}
function isValidDate(d) { //Check if a cell is a date, reference from https://stackoverflow.com/a/17110249
if ( Object.prototype.toString.call(d) !== "[object Date]" )
return false;
return !isNaN(d.getTime());
}
SAMPLE DEMONSTRATION:
Two methods below on how to use the FINDDATE custom function:
Method 1:
Method 2:
Method 3: Using FINDDATE on a different sheet

How to autofill date in google sheet when i enter value in cell A

If I enter "paid" text in cell A in sheet, I want to auto pull the current date in cell B. If the cell is empty, it should not pull the date. Like:
--------------------------------------
A | B
--------------------------------------
Paid | 2/25/2018
----------------------------------
Paid | 2/26/2018
----------------------------------
empty cell |
----------------------------------
empty cell |
I tried to use =ArrayFormula(IF(A2:A81=paid),"paid",(NOW()))
But getting error. Is their any way to do it?
Try this:
=ArrayFormula(IF(A2:A81="paid", NOW(),""))
If you never want the date to change, you need to use script like this:
function onEdit() {
// writes the current date to the cell to the right on the row when a cell in a specific column is edited
// adjust the following variables to fit your needs
var sheetNameToWatch = "Sheet1";
var columnNumberToWatch = /* column A */ 1; // column A = 1, B = 2, etc.
var valueToWatch="paid";
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getActiveCell();
var val=sheet.getActiveCell().getValue()
if (sheet.getName() == sheetNameToWatch && range.getColumn() == columnNumberToWatch && val==valueToWatch) {
var targetCell = sheet.getRange(range.getRow(), range.getColumn()+1
);
targetCell.setValue("" + Utilities.formatDate(new Date(), "GMT", "MM/dd/yyyy"));
}
}
There is not a way to do this with a formula that I know of. It can be made shorter, but script is still required:
function onEdit(e) {
if (e.source.getSheetName()=="Sheet1" && e.range.getColumn() == 1 && e.range.getValue() == "paid") {
e.range.offset(0,1).setValue(new Date());
}}
Works perfectly, thank you!
I changed it a little, so the date would auto populate if I entered anything into the column. I keep several spreedsheets for accounting, billing, and business tracking. One of them is hours. So when I enter the hours "1" or "5.5", the date to the left will populate. Love it! Thanks.
function onEdit() {
// writes the current date to the cell to the right on the row when a cell in a specific column is edited
// adjust the following variables to fit your needs
var sheetNameToWatch = "Sheet1";
var columnNumberToWatch = /* column A */ 2; // column A = 1, B = 2, etc.
var valueToWatch="paid"; /* isn't doing anything */
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getActiveCell();
var val=sheet.getActiveCell().getValue()
if (sheet.getName() == sheetNameToWatch && range.getColumn() == columnNumberToWatch && val!= "" /* I changed this var value so if I input anything, it will update the date */) {
var targetCell = sheet.getRange(range.getRow(), range.getColumn()-1 /* changed this to "-1" so it will input to the left column */
);
targetCell.setValue("" + Utilities.formatDate(new Date(), "GMT", "MM/dd/yyyy"));
}
}
Not quite an exact answer, but a simple and quick way to add the current date to a cell is:
Command + ; (on Mac keyboard, Ctrl otherwise)

Google Sheets Lookup Tool Assistance

I've taken it upon myself the learn how to "excel". That made a little more sense in my head, but hey.
I have built a "lookup tool" which can be viewed here.
The "Dishwasher search" is working as intended. You can search by noise level or decor panel height to create a list of suitable models then pull the data into an individual search by product code/model no.
I decided to make it a little more difficult and created one for Ovens.
The Layout is like this; Main search>Single Oven Database>Double Oven Database>Built-under oven database.
My goal is to achieve the same search facilities as the "Dishwasher tool", however I have been unsure how to search (Vlookup) from different sources.
I have tried creating a "Master DB" using the formula below;
={Importrange("1mY13e-75dBYfKgkjV8dFFFEvxC838nGNxPrUdusc0PA", "'Single Ovens'!$A:$F");Importrange("1mY13e-75dBYfKgkjV8dFFFEvxC838nGNxPrUdusc0PA", "'Double Ovens'!$A:$F");Importrange("1mY13e-75dBYfKgkjV8dFFFEvxC838nGNxPrUdusc0PA", "'Built-Under Ovens'!$A:$F")))}
However, it only seems to pull data from the first range not the others unless I do it horizontaly rather than vertical, but horizontal wont work with my Vlookup formula (To my knowledge).
The other method I have tried is using this code;
=IF(AND($A$19="Single Oven",$A$4>0), Vlookup($A$4,'Single Ovens'!$B:$F,1,False),IF(AND($A$10="Double Oven",$A$4>0), Vlookup($A$4,'Double Ovens'!$B:$F,1,False),If(AND($A$10="Built-Under Oven",$A$4>0), Vlookup($A$4,'Built-Under Ovens'!$B:$F,1,False),IF($A$10="Single Oven",Vlookup($A$7,'Single Ovens'!$A:$F,2,False),IF($A$10="Double Oven", Vlookup($A$7,'Double Oven'!$A:$F,2,False),If($A$10="Built-Under Oven", Vlookup($A$7,'Built-Under Oven'!$A:$F,2,False)))))))
The above code was inserted and was "meant" to Vlookup all 3 sheets and pull "product Code" through to populate Cell D4 on sheet 'Ovens'.
Now, I'm a bit of a novice at this but I'm working to understand it all :)
Any suggestions you guys can make or point me in the right direction?
Edit -
Sorry guys. It was rude not to post my solution. I have changed my Importrange function to =Importrange("XYZ",""'Single Ovens'!$A2:$F200") and repeated this 3 times with a gap of 200 "rows" between each one. Not a solution, but a viable alternative. My friend is currently working on a script for me to achieve this. The Vlookup formula no longer needs to be as complex thanks to the importrange formula simplifying matters.
So after discussing the problem with McSheehy, and the problem is actually this.
How to get data from ONE spreadsheet, multiple sheets of my choice.
and write To MANY spreadsheets, Multiple sheets within those spreadsheets, of my choice.
Once that data is in the right place, the current formulas should work or can be adapted easily.
I came up with a script solution,
The user creates a settings sheet in the source sheet.
In A2 downwards, Target spreadsheet keys, B2 downwards, Source sheet names you wish to include from current sheet. C2 downwards is the target SHEET names, if you wanted to write data to more than one sheet.
Bits of code are annotated to help explain McSheehy's questions on how it works.
If anyone has any improvements to suggest, and I'm sure there are some, particular the headers bit. (its not needed, but my clearContent/clearConents line kept flipping out), I'm all ears.
Thanks
function getOvenDataV5(){
var settingsSheetName = "monkey_settings";
/* DO NOT EDIT BELOW THIS LINE */
var ss = SpreadsheetApp.getActiveSpreadsheet();
var settings = ss.getSheetByName(settingsSheetName);
// this bit has been edited, note the getValues, not getValue, as we want the whole column now not just a single cell.
var targetSheetsValues = settings.getRange("C2:C").getValues(); // this gets the target sheet names from the settings sheet
var targetSheets = []; // And array added to throw target sheet names into, as there is more than one.
// the reason we use arrays and loops (later on), is because the script has no idea how much data to expect.
// so we go through whatever it's grabbed, the stuff it thinks is data, but we check it later on.
// only a simple check. Our check is that it cannot be blank. ""
// then stuff it in an array, a handy thing to store data, for use later on.
var sSheets = settings.getRange("B2:B").getValues();
var sourceSheets = [];
// new loop below to get the target sheets names. We'll use this in the write bit later.
for(var i = 0; i < targetSheetsValues.length;i++){
if(targetSheetsValues[i][0]!=""){
targetSheets.push(targetSheetsValues[i]);
}
}
for(var i = 0; i < sSheets.length;i++){
if(sSheets[i][0]!=""){
sourceSheets.push(sSheets[i]);
}
}
var dKeys = settings.getRange("A2:A").getValues();
var sKeys = [];
for(var i = 0; i < dKeys.length;i++){
if(dKeys[i][0]!=""){
sKeys.push(dKeys[i]);
}
}
var data = [];
for (var i = 0; i < sourceSheets.length;i++){
var values = ss.getSheetByName(sourceSheets[i]).getDataRange().getValues();
for (var x = 1;x < values.length; x++){
if(values[x][0]!= ""){
data.push(values[x]);
}
}
}
// Below is an array of your column headers, the script was being annoying when clearing sheet data, so decided to clear the whole damn sheet
// then write the headers via here instead
var headers = [["Model No", "Product Code", "Brand", "Model No", "kW", "Amp"]];
for (var i = 0; i< sKeys.length;i++){
var tss = SpreadsheetApp.openById(sKeys[i]);
for(var x = 0; x < targetSheets.length;x++){ // this loop, within the keys loop, goes through the target sheets array
var target = tss.getSheetByName(targetSheets[x]); // this loads the target sheet, one by one
var range = target.getRange(2,1, data.length, data[0].length); // this gets the cells to write to
target.clearContents(); // clear the sheet before writing data
target.getRange("A1:F1").setValues(headers); // write the headers to a1:F1 in target sheet
range.setValues(data); //write the data
}
}
}
I dont know if they will be of any value but here are two things that i wrote in script.
The follow is a vlookup script to set or return to memory with hints of query ish abilites.
//~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`
//--//Dependent on isEmpty_()
// Script Look-up
/*
Benefit of this script is:
-That google sheets will not continually do lookups on data that is not changing with using this function as it is set with hard values until script is kicked off again.
-Unlike Vlookup you can have it look at for reference data at any Column in the row. Does not have to be in the first column for it to work like Vlookup.
-You can return the Lookup to Memory for further processing by other functions
Useage:
Lookup_(Sheetinfo,"Sheet1!A:B",0,[1],"Sheet1!I1","n","y");
//or
Lookup_(Sheetinfo,"Sheet1!A:B",0,[1],"return","n","n");
//or
Lookup_(Sheetinfo,"Sheet1!A:B",0,[0,1],"return","n","n");
//or
Lookup_(Sheetinfo,"Sheet1!A:B",1,[0],"return","y","n");
//or
Lookup_("cat","Sheet1!A:G",4,[0],"Database!A1","y","y");
-Loads all Locations numbers from J2:J into a variable
--looks for Location Numbers in Column 0 of Referance sheet and range eg "Data!A:G"
---Returns results to Column 3 of Target Sheet and range eg "test!A1" or "1,1"
*/
function Lookup_(Search_Key,RefSheetRange,SearchKey_Ref_IndexOffSet,IndexOffSetForReturn,SetSheetRange,ReturnMultiResults,Add_Note)
{
var RefSheetRange = RefSheetRange.split("!");
var Ref_Sheet = RefSheetRange[0];
var Ref_Range = RefSheetRange[1];
if(!/return/i.test(SetSheetRange))
{
var SetSheetRange = SetSheetRange.split("!");
var Set_Sheet = SetSheetRange[0];
var Set_Range = SetSheetRange[1];
var RowVal = SpreadsheetApp.getActive().getSheetByName(Set_Sheet).getRange(Set_Range).getRow();
var ColVal = SpreadsheetApp.getActive().getSheetByName(Set_Sheet).getRange(Set_Range).getColumn();
}
var twoDimensionalArray = [];
var data = SpreadsheetApp.getActive().getSheetByName(Ref_Sheet).getRange(Ref_Range).getValues(); //Syncs sheet by name and range into var
for (var i = 0, Il=Search_Key.length; i<Il; i++) // i = number of rows to index and search
{
var Sending = []; //Making a Blank Array
var newArray = []; //Making a Blank Array
var Found ="";
for (var nn=0, NNL=data.length; nn<NNL; nn++) //nn = will be the number of row that the data is found at
{
if(Found==1 && ReturnMultiResults.toUpperCase() == 'N') //if statement for found if found = 1 it will to stop all other logic in nn loop from running
{
break; //Breaking nn loop once found
}
if (data[nn][SearchKey_Ref_IndexOffSet]==Search_Key[i]) //if statement is triggered when the search_key is found.
{
var newArray = [];
for (var cc=0, CCL=IndexOffSetForReturn.length; cc<CCL; cc++) //cc = numbers of columns to referance
{
var iosr = IndexOffSetForReturn[cc]; //Loading the value of current cc
var Sending = data[nn][iosr]; //Loading data of Level nn offset by value of cc
if(isEmpty_(Sending)) //if statement for if one of the returned Column level cells are blank
{
var Sending = "#N/A"; //Sets #N/A on all column levels that are blank
}
if (CCL>1) //if statement for multi-Column returns
{
newArray.push(Sending);
if(CCL-1 == cc) //if statement for pulling all columns into larger array
{
twoDimensionalArray.push(newArray);
var Found = 1; //Modifying found to 1 if found to stop all other logic in nn loop
break; //Breaking cc loop once found
}
}
else if (CCL<=1) //if statement for single-Column returns
{
twoDimensionalArray.push(Sending);
var Found = 1; //Modifying found to 1 if found to stop all other logic in nn loop
break; //Breaking cc loop once found
}
}
}
if(NNL-1==nn && isEmpty_(Sending)) //following if statement is for if the current item in lookup array is not found. Nessessary for data structure.
{
for(var na=0,NAL=IndexOffSetForReturn.length;na<NAL;na++) //looping for the number of columns to place "#N/A" in to preserve data structure
{
if (NAL<=1) //checks to see if it's a single column return
{
var Sending = "#N/A";
twoDimensionalArray.push(Sending);
}
else if (NAL>1) //checks to see if it's a Multi column return
{
var Sending = "#N/A";
newArray.push(Sending);
}
}
if (NAL>1) //checks to see if it's a Multi column return
{
twoDimensionalArray.push(newArray);
}
}
}
}
if (CCL<=1) //checks to see if it's a single column return for running setValue
{
var singleArrayForm = [];
for (var l = 0,lL=twoDimensionalArray.length; l<lL; l++) //Builds 2d Looping-Array to allow choosing of columns at a future point
{
singleArrayForm.push([twoDimensionalArray[l]]);
}
if(!/return/i.test(SetSheetRange))
{
SpreadsheetApp.getActive().getSheetByName(Set_Sheet).getRange(RowVal,ColVal,singleArrayForm.length,singleArrayForm[0].length).setValues(singleArrayForm);
SpreadsheetApp.flush();
if(/y/i.test(Add_Note))
{
SpreadsheetApp.getActive().getSheetByName(Set_Sheet).getRange(RowVal,ColVal,1,1).setNote("VLookup Script Ran On: " + Utilities.formatDate(new Date(), "PST", "MM-dd-yyyy hh:mm a") + "\nRange: " + Ref_Sheet + "!" + Ref_Range);
}
}
else
{
return singleArrayForm
}
}
if (CCL>1) //checks to see if it's a multi column return for running setValues
{
if(!/return/i.test(SetSheetRange))
{
SpreadsheetApp.getActive().getSheetByName(Set_Sheet).getRange(RowVal,ColVal,twoDimensionalArray.length,twoDimensionalArray[0].length).setValues(twoDimensionalArray);
SpreadsheetApp.flush();
if(/y/i.test(Add_Note))
{
SpreadsheetApp.getActive().getSheetByName(Set_Sheet).getRange(RowVal,ColVal,1,1).setNote("VLookup Script Ran On: " + Utilities.formatDate(new Date(), "PST", "MM-dd-yyyy hh:mm a") + "\nRange: " + Ref_Sheet + "!" + Ref_Range);
}
}
else
{
return twoDimensionalArray
}
}
}
//~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`
//~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`
//--//Dependent on isEmpty_()
//Find Last Row on Database
function getFirstEmptyRowUsingArray_(sheetname)
{
var data = SpreadsheetApp.getActive().getSheetByName(sheetname).getDataRange().getValues();
for(var n = data.length ; n>0 ; n--)
{
if(isEmpty_(data[n])==false)
{
n++;
break;
}
}
n++;
return (n);
}
//~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`
The Following is a ImportRange script because I hate how =importrange() requires you to "request access" on every new formula. If that importrange is embedded you have to take it out and request access and re-embed it. Also a lot of times the formula just breaks. so:
//~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`
//Script Based ImportRange
//Example importRange_('0AodPsggrbsh1dDNH............','Main4NS','A:G','Common','C7','y')
//Explanation importRange_('Importing Spreadsheet Key or URL','Importing Spreadsheet Tab Name','Importing Spreadsheet Tab's Range','Destination Spreadsheet Tab Name','Destination Spreadsheet Tab's placement','Will add note to the first cell of import')
function importRange_(Source_Key,Source_Sheet,Source_Range,Set_Sheet,Set_Pos,Add_Note)
{
var SourceTypeCheck = Source_Key.indexOf("https://");
if(SourceTypeCheck >= 0)
{
var Load = SpreadsheetApp.openByUrl(Source_Key).getSheetByName(Source_Sheet).getRange(Source_Range).getValues();
var Name = SpreadsheetApp.openByUrl(Source_Key).getName();
}
if(SourceTypeCheck == -1)
{
var Load = SpreadsheetApp.openById(Source_Key).getSheetByName(Source_Sheet).getRange(Source_Range).getValues();
var Name = SpreadsheetApp.openById(Source_Key).getName();
}
var RowVal = SpreadsheetApp.getActive().getSheetByName(Set_Sheet).getRange(Set_Pos).getRow();
var ColVal = SpreadsheetApp.getActive().getSheetByName(Set_Sheet).getRange(Set_Pos).getColumn();
if(Add_Note.toUpperCase() == 'Y')
{
SpreadsheetApp.getActive().getSheetByName(Set_Sheet).getRange(RowVal,ColVal,1,1).setNote("Import Script Updated On: " + Utilities.formatDate(new Date(), "PST", "MM-dd-yyyy hh:mm a")+"\nSS Name: "+Name+"\nRange: "+Source_Sheet+"!"+Source_Range+"\nSS Key: "+ Source_Key);
}
SpreadsheetApp.getActive().getSheetByName(Set_Sheet).getRange(RowVal,ColVal,Load.length,Load[0].length).setValues(Load);
SpreadsheetApp.flush();
SpreadsheetApp.getActiveSpreadsheet().toast('At: '+Set_Sheet+'!'+Set_Pos,'Import Completed:');
}
//~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`
Same thing stands. If you have and ideas for improvement let me know. If you find a way to integrate it, cool beans, Post some code of how you used it.
:)

Resources