Sheets Script - Copy Formatting of Existing Rows to New Rows - google-sheets

I've created a Flash cards template in Google Sheets to use for studying TERMS & DEFINITIONS.
There's an additional functionality I would like implemented with a script that creates new rows according to the format already in use.
DESIRED RESULT
When a user fills out all 25 rows of cards (50 total because 2 columns of cards), I want the "Plus sign" button in the top right of the sheet to be assigned a script that would copy the existing formatted rows and checkboxes to create new cards (essentially copying down the existing formatting).
The ability of this functionality allows users to customize the amount of Flash cards they want to add to the sheet without having to manually COPY and PASTE the rows themselves.
In the provided image, the last rows would be 100:103, COPIED, then pasted beginning on row 104
CHALLENGES
If newly created rows were added and a user wanted to add more, the last row would differ so it would not be rows 100:103
Since the rows would be blank (no entered data), how can Google Sheets determine where the last row is? Can a user defined dialog box open and tell Sheets where the new row should begin? If so, is it possible to also have a user defined number of desired rows created (i.e., Insert 5 rows of cards)?
Please review the following image as a reference.
Copy_rows
Thanks in advance!
Cas

Related

How to automatically expand rows based on an intervall of accounts 3000-3999 (accounting)?

I'm trying to figure out how one can expand rows automatically using formulas or appscript in Google Sheets.
The goal is to create a standard Profit and Loss report with automatic expanding rows based on intervalls, such as 3000 - 3999 for revenue. The issue today is that, by not using Pivot tables, i cant get the rows to expand and push the other rows underneath downwards. I have to manually insert a new account and rows if new accounts are added.
Does anyone have any tips? Is there an add-on or an appscript that allows us to perform such an action?
I've tried using Filter/Sort function with empty spaces underneath each group to make room for new accounts and hidden the rows, but its not a very scalable solution. I've also tried using Pivot tables but cant expand rows automatically that way either. I get a #ref if the rows collide with new accounts.
3000
3001
3002
(blank)
(blank)
(blank)

How do I add formulas to additional rows of my Google sheet automatically?

All my rows have the same formulas. I want it to be copied to the newly added rows automatically. Sheets provide us with 1000 rows initially and an another 1000 or so can be added subsequently as per requirement. I want sheets to automatically copy paste formulas to the newly added row.
I couldn't edit the sheet (because of protection on the sheet) but try clearing out alll contents of column T and then enter in T1
={"SPOT SURVEYOR'S MOBILE NO"; Arrayformula(if(len(S2:S), IFERROR(vlookup(S2:S,$EE$2:$EO,5,0)),))}
and see if that works?

I can't figure out how to filter or query in Google Sheets without returning a bunch of blank strings appended to actual data

I'm at my wit's end on trying to figure out why filtering/querying in Google Sheets is so broken. I have a sheet with some data about practice exams I'm taking and I'm attempting to pull some data from that sheet to another sheet for calculating statistics. I've made a shareable document with the pertinent stuff so you can see what I mean.
My raw data is in the TestScores sheet and I made a TESTSTATS sheet to test different methods of pulling data from TestScores. In my example, I'm only trying to pull unique dates from range TestScores!B2:B and I've added a few different methods to do so in TESTSTATS (removed the equal sign from each one so each can be tested on its own by putting in the equal sign).
The methods I've tried:
=UNIQUE(TestScores!B2:B)
=UNIQUE(FILTER(TestScores!B2:B, TestScores!B2:B<>""))
=UNIQUE(FILTER(TestScores!B2:B, TestScores!B2:B<>0))
=UNIQUE(FILTER(TestScores!B2:B, NOT(ISBLANK(TestScores!B2:B))))
=UNIQUE(QUERY(TestScores!B2:B, "select B"))
=ARRAY_CONSTRAIN(UNIQUE(QUERY(TestScores!B2:B, "select B")), ROWS(UNIQUE(TestScores!B2:B))+1,5)
You'll see that each one, when activated by adding the = in front of the formula returns the proper data, but also appends 500 empty rows which look empty, but are in fact blank strings (""). This makes it difficult to work with because there are a lot of calculations in my sheet that depend on one another. I also do not want to specify an explicit end to my ranges and would prefer to keep them open ended (B2:B instead of B2:B17) so everything updates automatically as new records are added.
What am I doing wrong? Why are the returned data appended with a bunch of empty cells, and why 500 specifically (seems arbitrary considering my source data is 29 or 30 rows depending on whether or not you include headers)?
Starting with only two rows in TESTSTATS more rows have to be added for somewhere to place the output. It seems Google choose to do so 500 rows at a time (from the last required cell). "Why?" would have to be a matter for Google.
If you know 14 rows are required for the output and increase the size of TESTSTATS to 16 no more rows will be added. Since you want room for expansion you can't extend to 16 and avoid further issues but you could allow some room, say to 30 rows, and delete the few extra, or, if 30 becomes insufficient (when sheet shoots up to say 540 rows) delete the rows not required but set the sheet size to say 60 rows - and so on.

Number increment in Google Sheets formula

In a Google Sheets database, I have a formula which I have built in order to allocate a reference number to a series of companies.
Each company should have its unique number in the form of RET00XX where XX will represent the unique company number. I would like these numbers to be sequential, starting on 1 and going on +1 after that.
Whenever a new company is inserted in the database, the formula should be able to attribute it a reference number. It should also be able to verify if the company already exists in the database and, if so, automatically attribute it the company's unique reference number, instead of creating a new one.
The company names are in cells of column B.
This is the formula I have built (an example of the one in row 2):
=ARRAYFORMULA(IF($B2<>"",IF((COUNTIF($B$1:$B1,$B2)>0),INDEX($A$1:$R2,MATCH($B2,$B$1:$B1,0),12),CONCATENATE("RET00",ROW($B2))),""))
The steps it takes are:
It verifies that column B in the correspondent row is not empty;
With the COUNTIF function, verifies that the company does not exist in any of the previous rows;
If the company does exist, it attributes the correspondent reference number through the INDEX function;
If the company doesn't exist, it attributes the company a new reference number with the CONCATENATE and ROW functions.
The formula is largely working, although there are some problems.
Users adding to this database have the habit of adding entries by inserting rows in the middle of the database. This makes it so, due to the way the formula is built, that company unique reference codes change each time that happens. I believe this is partially due to the fact that I use a ROW function. Also, given that new rows are inserted in the middle of the database, the formula should be able to verify is the company already exists not only by looping through all previous rows but rather through all rows (if a new row is inserted, the formula will only verify previous rows, when the company could be in the rows after the new one).
How can I attribute sequential numbers in a formula without reference to ROW? Also, how can I make sure that the spreadsheet verifies for all rows of column B instead of just the ones before the inserted row?
apply this formula in your sheets,
=ArrayFormula(if(B2:B<>"",row(A2:A)-1,""))
More information regarding this please visit this link : https://infoinspired.com/google-docs/spreadsheet/auto-serial-numbering-in-google-sheets/
Solution that is independent of starting row number
These examples will allow you to generate incrementing values in your formulas.
Incrementing integers, zero based:
The values will be: 0,1,2,3, etc.
Note: The address "$A$2" represents the cell of your top row. It should be changed to whatever cell your actual top row is. The nice thing about this method is it it will not break if you insert new rows above the start position of your formula.
=(ROW()-ROW($A$2))
Integers, one based:
The values will be: 1,2,3,4, etc.
=(ROW()-ROW($A$2) + 1)
Dates:
The values will be: 2000-01-01,2000-01-02,2000-01-03, etc.
=Date(2000,1,1) + (ROW()-ROW($A$2))
All Even Numbers:
The values will be: 0,2,4, etc.
=(ROW()-ROW($A$2) * 2
Short answer
Use Google Apps Script
Explanation
Using spreadsheet functions to set an ID on a live spreadsheet used as a database is very risky as the values will be recalculated when changes be made to the spreadsheet content.
Instead of using a formula use a script to add a "fixed value". Scripts could be called automatically on events like cell edits and row insertion, by using a custom menu or side panel, from the script editor or by time-driven triggers.
The following Q&A from Web Applications shows several ways to set a sequential number:
Can I add an autoincrement field to a Google Spreadsheet based on a Google Form?
This other from SO could be helpful too:
Auto incrementing Job Reference
Insert 1 in the first cell and paste the formula below in the following cells.
=INDIRECT(ADDRESS(ROW()-1,COLUMN())) + 1
Add number on very first row and type the formula from next cell
i used =A1+1 to get incremental number to index tasks on each line.

Creating a totals page for timesheet

I have a spreadsheet that we use as a Time sheet.
It's made up of approx 80 tabs (Names of employees)
We have a front page, simply called "Totals"
This adds up a fortnights worth of hours into several Columns
When we make changes, we have several scripts to help make life easier
(Delete old sheets, duplicate master sheet, rename duplicate sheets, protect ranges etc...)
One script that we don't have though is one to create the totals page faster.
Our totals page has the name of every employee in column A,
We use these names in our scripts to rename tabs etc...
I would like a script to link the calculations on the Totals Page, to the sheet and cell of every individuals tab.
We do this by manually by entering =nameoftab!C47 in the cells of the totals page.
What i want to do is =Totals!A3 C47
So the cell pulls the sheet name from the name list on the left hand side, and points to C47 in the appropriate tab.
This would allow us to add new people to our time sheet by simply adding their name to column A and not the formulas for ordinary time/overtime/travel time/allowances etc...
Can this be done?
I have played with several formulas/scripts to make this easier but to no avail
(Please let me know if you need me to be more specific)
Try this simple formula:
=indirect("'nameoftab'!C47")
or in your case:
=indirect("'" & Totals!A3 & "'!C47")
where Totals!A3 is cell with sheet name.

Resources