How to copy new data in Googlesheet in the same sequence - google-apps-script

I have two googlesheets, In one google sheet (let's call it A) I am uploading the data using R cron and in another sheet (let's call it B) I'm importing the data from A using importrange formula.
In B, I am importing the data in sheet1 but I want to automatically copy the data from Sheet1 in Sheet2 whenever the Sheet1 gets updated. Also, I want to ensure that the new updated data gets append in Sheet2 without changing the sequence of previous records.
For Example,
If in B, Sheet1 has 5 records as mentioned below then copy it in new tab as Sheet2 and if in Sheet1 new data gets upload (suppose now there are 10 records in sheet1) then new uploaded five records should get appended in Sheet2 without changing the sequence and anything updated against records 1-5.
ID Name Date
1 ABC 2020-01-01
2 ART 2020-01-02
3 XUZ 2020-01-03
4 AFI 2020-01-03
5 SSR 2020-01-02
Sheet - https://docs.google.com/spreadsheets/d/1pY5dvlrEf39ul7sqmzyBI1Hwoplh9_7eNGveeVfUQZA/edit?usp=sharing

I've added a tab, Sheet2-GK, to your sheet. This demonstrates using the ID value as an index in Sheet2, to allow manual data to be entered alongside dynamic data, which is updated from Sheet1 by formula.
The key formula, in Sheet2!B2, would be:
=ARRAYFORMULA(VLOOKUP(A2:A6,Sheet1!A$1:C,{2,3},0))
Without more sample data, I can't test the results, but let me know if this works for you, as you add fresh data to Sheet1.

Related

Copy cells from exported sheet to MainSheet filtered by Dates with a one click-button

I am very new to Google sheets and need help :-) Thnx in advance. :-)
Info: Google Table with 2 sheets
Sheet1: 'BackBuffer':
header 1
header 2
-
-
22.11.2022
23.11.2022
Sheet2: 'Export':
MSN-No
Quality Date
Handover Date
12345
25.11.2022
23.11.2022
67890
23.11.2022
27.11.2022
11123
23.11.2022
27.11.2022
My Problem to solve:
I want to programm a button which picks the MSN Number from Sheet2 and copies it to the corresponding Cell above the matching Date in Sheet1. The Quality Dates should be copied in nonbold and the Handover Dates in bold. This means in cells of Sheet1 Row1 there can be multiple MSN Numbers which i want to be stacked on top of each other or lined up with a comma. MSN-No should not be just replaced (Maybe it is also possible to sort the MSNs and display the bold MSNs below the not bold ones).
For example one Cell in SHeet1 Row1 can look like this:
header 1
header 2
-
67890, 11123, 12345
22.11.2022
23.11.2022
Also the Dates of MSNs in Sheet2 'Export' can change from week to weeek. So when i load in the new Data and click the button, i want the MSN-Numbers in Sheet1 to be updated to the correct Date in Row1 and delete the old obsolete Date which doesnt match to the new Data in Sheet2.
I hope you can understand my problem and can help me out. Many many thanks in Advance.
BR Musti
I am unfortunately a noob in google sheets programming.

How to write data into a specific range based on a variable

In the image below, Table 1 is an editable table where a user can change the values. Table 2 is a master table that I want to update with the changed values from Table 1. The unique identifier for each table is the Full Name (Column A). In this example, I'd like to:
Get the data from Table 1 associated with the Full Name entered into B1 (Washington, George).
Update the right record in Table 2 (row 13) with the values from Table 1.
Table 1 and Table 2
I know that I can use getvalues() and setvalues() to get the data from Table 1 and write it into Table 2. I'm having trouble figuring out how to get the right range (row 6 in Table 1 for the getvalues() function and row 13 in Table 2 for the setvalues() function) based on the value in B1 (Washington, George).
If I were using Excel VBA, I'd do a search in Table 1 and Table 2 for the value in B1 and then select the entire row. I've read articles about how to get a range based on A1 notation, user selection, and column/row identification, but I can't find anything related to getting a range relative to the location of a specific value in the data set.
Use this to read the data in the sheet:
const sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');
const data = sheet.getDataRange().getValues();
Follow with this to find the row index of searchValue:
const keys = data.map(row => row[0]);
const rowIndex = keys.indexOf(searchValue);
To write a values array in the row, use this:
sheet
.getRange(rowIndex, 1)
.offset(0, 0, 1, values.length)
.setValues(values);
Some of the best resources for learning Google Apps Script include the Beginner's Guide, the New Apps Script Editor guide, the Fundamentals of Apps Script with Google Sheets codelab, the Extending Google Sheets page, javascript.info, Mozilla Developer Network and Apps Script at Stack Overflow.

Google Sheets: Every time a cell changes I would like a new row in a database the the cell value + time stamp

I have an Investment dashboard on Google Sheets that updates when i click a button.
I would like that each time the sheet is updated to create a new line in a Database to show my profit/loss over time.
for instance: A1 shows Profit/ Loss. B1 shows Profit/ Loss %
On update: A1 and B1's value should reflect in the next row on my database sheet ("Database") in the following format:
Coulomb A: Date & Time.
Coulomb B: A1 value
Coulomb C: B1 Value
Hope that makes sense. Thanks in advance.
Have your button script compare the sheet's current data to the new data and calculate the differences. Store this data into a 2D array, and have your script paste it onto a new row on your database sheet.
If this does not clarify the issue, please elaborate.

IMPORTRANGE referring to a cell with link instead of link itself. And Range using cell value instead of sheet name

I'd like to IMPORTRANGE("http://page","Sheet!A11:F")
Where the page is a link located in a cell on the current sheet, and the range is also in a cell on the current sheet.
For example: IMPORTRANGE("'C8'","'A1'!All:F") Something like that.
My overall goal is to be able to copy the current workbook, add a sheet, put a reference number in A1, then have the sheet automatically pull data (using an A1 vlookup from a master list) from the correct sheet in another workbook without having to manually relink eveyrthing. Just want to put the unique ticker in A1.
The application is there is a 'Master Deal List' workbook. Each row has a different deal with a unique 3 digit 'ticker' in Column A and the deal's sheet in another workbook link in column F. This second workbook (Deals) with distribution data named with the same 3 digit ticker. Finally each investor in each deal has a 3rd workbook which needs to pull distribution amounts from the right sheet in the Deals workbook.
Got it, answer is here:
https://infoinspired.com/google-docs/spreadsheet/dynamic-sheet-names-in-importrange/
Answer:
IMPORTRANGE("http://page", A1&"!A11:ZZ")

summary of several google sheets in one another sheet

Hi have several sheet in a single google sheet for each of the months with some data. I want t have a summary sheet (annual) with some info I am after.
For example, in a sheet called Jan I have the following
Cell A B C
Date Cat Amount
05/01/16 Shop 100
10/01/16 Other 50
In another sheet (called Feb) in the same file, I have
Cell A B C
Date Cat Amount
07/02/16 Shop 200
11/02/16 Other 500
Now, I want to have another sheet, preferably in the same file, the following.(which is accumulation of all data in the two sheets above for just one category)
05/01/2017 Shop 100
07/02/16 Shop 200
my question is what is the formulae I good use to get above (I do not want to copy paste)
=query({Jan!A:F;Feb!A:F},"select *")
Try changing A to *. You could also try to use Col1 Col2 instead of A or B. I think it would work.
Try the below in sheet 3 in A1
={IMPORTRANGE("Sheet1!A1:D");IMPORTRANGE("Sheet2!A2:D")}
It will combine sheet1 data and sheet2 data in sheet3