Google Sheets: Automatic add rows in multiple sheets based on Master Sheet - google-apps-script

I have a Google Sheet with multiple tabs. The first one is the Master Sheet where I have some basic location info. In the other sheets I'm transferring those basic info through "Importrange" so I have some columns dynamically changing and some that are static and the users are able to update. Although, if I add a row in between my data at the Master Sheet it will only change the dynamic columns (updated from importrange) but the rest columns won't change- which will mess with the updates.
Is there any way/ script where I can add rows in the other sheets automatically when a row is added in the master one?

You are describing a row misalignment issue. See Lance's thorough treatment of the issue and how it can be dealt with in some cases. It is a lengthy read, and too long to repeat here.
If you are simply trying to let each user to edit "their" data, you can also keep all the data in the master sheet and use filter views to decide which rows to show at a time. This feature lets multiple simultaneous users sort, filter and edit a sheet without disturbing each other.
For additional ease of use, you can insert links in the frozen section of the sheet to easily switch between filter views, instead of having to go to Data > Filter views to switch. See the Filter views example spreadsheet for an illustration.

Related

Syncing a List between different sheets keeping properties sticked to a row

Maybe the title is not explicit enough, but what do I want to achieve, is:
I want to have a single place to edit a list (customers) with some metadata, to be used across the entire spreadsheet.
Some sheets may contain editable data as rows tied to the 1st column with the customer Ids. E.g. prices for services for each Customer for each month.
So, when I add an entry (Customer) to the 1st (master) sheet, it appears in the pricing table and doesn't break the existing entries (the rows remain connected).
So far I've not found any native solution for this. Should I look for extensions fo this, or code it using the app script?

get sheet data without the hidden columns

I am currently working on GAS project, for the moment I have a table in a sheet and the idea is that my collaborators will be able to choose the format of the table, which column and which row they want to save. I thought about using the hiding column and row features but is it possible in my apps script to get only the data which they chose to save and not the hidden data ? Thank you for you answers
Apps Script works analogously to the Sheets UI
Explanation
If from the user interface you select the desired data by "click&drag", the hidden columns located between the start and the end column will be also selected (and copied). Instead you need to select the data of interest manually with "Ctrl" and click, see here.
How to transfer this to Apps Script?
Apps Script features the method sheet.isColumnHiddenByUser(columnPosition) (and isRowHiddenByUser, isRowHiddenByFilter etc.). You can use it to select only the ranges / the values of a datarange in columns and rows that are not hidden.
This implies the implementation of loops and conditions statements, so is not necessary an elegant solution.

In Google Sheets, how to lock or prevent sorting

I have a shared Sheet that multiple people edit. The data is in a very specific order for our needs. I need to prevent people from sorting this sheet which messes up the data. I am open to an Apps Script or settings-based solution.
Protecting the sheet really isn't an option as so many ranges take edits from numerous people
Ideally, the sort menu item will be grayed out. Secondarily, override the sort button to have no action. Alternatively, have code to do something like cancel the sorting action or reverse the sort.
How about this, it counts the number of rows and locks them from sorting
function freezeRows() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var range = ss.getDataRange().getValues().length; //gets # of rows
ss.setFrozenRows(range);//freezes all rows
}
can use the onOpen and onEdit triggers so whenever it's opened it's ran, and also runs when anything is edited.
I just found out how to limit some users to sort the entire sheet or even sort a column. If you want to restrict user "JOHN" you need to :
Give him editor rights to the sheet.
Create an empty column (let's say it's column A)
Click Data. Protected sheets and ranges. Restrict JOHN from editing column A.
When John will try to sort the sheet or a column, instead of being sorted, it will create a temporary filter because he has not access to the entire sheet :)
You can also deny him access to the sheet's first line (or create an empty one), so he cannot filter any column (you need to have access to the entire range to do so)
Let me know if that works for you as well!

How to add a button in Google Sheets that Automatically Adds Columns and formulas

I would like to add a script to a button I created in Google Sheets. I would like the button to add a new column before my "Month Loss" column. I would like the new column to copy the formulas and formatting of the column to the left.
This will provide an easy way to track my body measurements and help to determine calculate my body fat percentage.
Here is a link to my sheet: https://docs.google.com/spreadsheets/d/1DP0SQpU16YEfPWoE8IRknoqQWu0wrFagzhLflVOkn8M/edit?usp=sharing
A Pivot Table has been created though script. if you try to programmatically update the range, there is no way either because named ranges need to be deleted then re-added which causes on the pivot.
if you are adding the new row by script, do not append it to the end. instead keep a fake row at the end and insert the new row just before it. your range (named or not) will update.
Even for the google forms case you might get it to work by pre-adding all blank rows to the response sheet and make the named range include the blank ones too.
Found this Stack Overflow ticket discuss about Pivot Table, you may also check the solution offered by the community: Google Spreadsheet Pivot Table Range Update Using Scripts

Linking google forms to master & children spreadsheets with automatic updates

I have a two-part question about master/child relationships in workbooks. I have beginner experience with writing code for excel & google spreadsheets so any extra detail would be truly appreciated.
Here is what I'm trying to achieve:
I want to make a google form to collect a set of data for (potentially 100's of people). The option to make changes to the form after submission will be enabled, so the data flow will be pretty dynamic. I've gotten as far as setting this up and creating the master spreadsheet where I can view all of the responses. But there's too much information in one spreadsheet and I'd like to make some child-workbooks to simplify the viewable data for various needs. So here are my questions:
1) How would I write the script to create a child worksheet from the master worksheet with these conditions: on run create a new worksheet called i.e "Child 1-Basic Info", delete all the columns and shift left with the exception of the ones I explicitly want to keep (based on the cell value) i.e "Name", "Age" & "Interests". Bear in mind I would want to eventually create multiple children workbooks, but basically do the same job each time. Just different column parameters i.e "Child 2-Education Info".
2) Along with this, I want to make sure that these children will be automatically updated every time someone submits a new response from my form or updates one they have already submitted. Essentially, the goal is to have any changes in the master ripple into all of the children. Also keep in mind that every time someone submits a new form, the row numbers will change. So the children will need to also recognize this change and update accordingly.
Thank you all in advanced!
With the QUERY() function, you can have secondary sheets that will dynamically update, with no need to use scripts at all. See more here.
Here's an example, a spreadsheet with rows of form-submitted data:
On a secondary sheet in the same spreadsheet, cell A1 contains a query formula that selects only the columns you asked for, "Name, Age, and Interests".
Every new form submission or update will result in recalculation of the query, so it will be kept up-to-date with no further intervention.