Google sheets - protect sheet except small range - exception

My concern is simple: I want to protect the whole sheet except 1 cell, which is a drop down menu. I want them to be able to change that value but impede the edition of the rest of the sheet.
Basically I need the inverse option of protection. Protect the sheet and unprotect a particular range (in this case 1 cell)
Thanks

Just found it.
Data - Protected sheets and ranges
Select 'Sheet' and will allow to select the exception range
See ya'll

Related

I want to transfer the content from one spread sheet to another spreadsheet(spreadsheet A to spreadsheet B) and also to enter records to B manually

I want to transfer the contents from one spreadsheet to another spreadsheet(spreadsheet A to spreadsheet B) whenever if I do changes in spreadsheet A it has to be reflected in spreadsheet B. At the same time, I should also be able to add elements directly to spreadsheet B. I tried importrange function, it was transferring the contents from A to B but it is not allowing me to manually add things to spreadsheet B.
The best approach you could take for this is to use Apps Script.
Some methods which can be of help to you:
openById - which is used to retrieve each spreadsheet by their ids;
getSheetByName - which is used to retrieve the sheets from the spreadsheets;
getRange - which is used to retrieve the range in which the values can be found;
getValues - which is used to retrieve the values from the specified range;
setValues - which is used to place the values to the specified range;
Moreover, if you want to have the changes from one spreadsheet reflected on another, you can also make use of an onEdit trigger.
Reference
openById(id);
getSheetByName(name);
getRange();
getValues();
setValues(values);
onEdit(e).

How do I protect cells at given time (given in same row) in Google Sheets?

I've read that a Google script may be the solution, but given that I am not at all familiar with coding/VBA, I need some help.
Let's say my sheet looks like this (Sorry for the 'norwegian' date-format):
A
B
C
01.01.2021 14:00
Value W
Value X
03.01.2021 15:00
Value Y
Value Z
When the current time hits the value in column A, the values in column B and C should be automatically protected, so that only I/selected users can edit them later on.
The list goes on downwards for almost 50 rows. I have multiple users in this sheet, and everyone can edit the values in column B and C.
Any awesome helpers out there?
Answer
To protect a range in Sheets refer to the following documentation.
Explanation
The attached documentation explains how to apply protection to a range through the UI version of Sheets. This protection prevents the non-selected users from modifying a particular range. This way, you can choose to make the range modifiable by you or more users.
In case you need to implement a variation in the editing permissions on that range, you can use Apps Script. In this, there are tools such as Time-driven triggers that allow you to execute a function at a specific time. In addition, the Spreadsheet Service has a function called protect() to enable and disable protection to a particular range.
References
Protect, hide, and edit sheets
Apps Script
Time-driven triggers
Spreadsheet Service
Range: protect

Copying and pasting data in Google Sheets to another column

I have a dashboard that is reporting live data based on a growing customer database, and I am currently tracking the daily process by copying and pasting the data in the column into the next on a daily basis.
I'd like to create a script that automatically copies the values from an array (B:B) for example, into another sheet OR into the next available column to the right.
You may refer to the image below for further clarity.
Sample
I saw may threads on this but they were all about copying into a different row, as opposed to a different column.
Many thanks in advance!
The getLastRow() method is used to return the position of the last row that has content.
The getLastColumn() method is used to return the position of the last column that has content.
Therefore, in order to be able to copy the data into the next available column, I suggest you try this:
function copyColumn() {
var ss = SpreadsheetApp.openById("ID_OF_THE_SPREADSHEET");
var sheetFrom = ss.getSheetByName("SHEET_FROM");
var sheetTo = ss.getSheetByName("SHEET_TO");
var values = sheetFrom.getRange(NO_OF_THE_ROW_WHERE_DATA_STARTS, 3, sheetFrom.getLastRow(), 1).getValues();
sheetTo.getRange(NO_OF_THE_ROW_WHERE_DATA_STARTS,sheetTo.getLastColumn()+1,values.length,1).setValues(values);
}
The above script localizes all the data that needs to be copied by using the getRange() method and is copied by using getValues().
NO_OF_THE_ROW_WHERE_DATA_STARTS is the value representing the number of the row where your data starts (in your case the row of No of LP - Secured);
3 is the value representing the C column (where the data you want to be copied is located);
sheetFrom.getLastRow() is the value representing the end of the data you want to be copied;
1 is the value representing the number of columns that need to be copied.
Afterwards, the getRange() method is used again in order to be able to identify where the data needs to be pasted and setValues() in order to actually paste it.
Note: The above script works for different spreadsheets and/or different sheets OR for sheets in the same spreadsheet. If you want to use it for the latter case, you just have to put the name of your sheet instead of SHEET_FROM and SHEET_TO.
Moreover, I suggest you check the following links since they might be of help:
Sheet Class Apps Script - getRange();
Range Class Apps Script - getValues();
Range Class Apps Script - setValues();
Sheet Class Apps Script - getLastColumn();
Sheet Class Apps Script - getLastRow();

How to find out the order of sheets created?

This is important because the order of execution is based on the first created sheet to the last created sheet which ordinarily is not an issue but is an issue for circular references. Obviously I can put something in the name to remind me but there seems to be no pattern to the gid number and therefore have no way to know for already created spreadsheets with custom sheet names without painfully testing circular reference formulas.
This is not part of my question but here is an example to demonstrate why this is so important:
Step 1) File->Spreadsheet Settings->Calculation->Iterative Calculation(On)->Max number of iterations(1)
Step 2) Set up the following test formulas
Cell A1 =A1+1
Cell B1 =A1
Cell A2 =B2
Cell B2 = B2+1
You will notice that even though they formulas should have the same results they do not due to the execution order, now this example is just of a single sheet but invisibly the original sheet creation order is the order of execution when formulas reference other sheets.
The fastest solution that satisfies your request is to use the getSheets method to obtain an array where every sheet appears in the same order that Sheet shows in the user interface. Keep an eye on them, because if you move one sheet around in the user interface the array won't reflect the true order of creation.
Another approach, more precise than the former one, is to use the properties class to save a timestamp every time that a sheet is created. You can manage that with the setProperty and getProperties methods.

Google spreadhseet EVAL function

I have a google spreadsheet with different sheets, each one representing a different week.
For example:
1/12 - 1/16
1/19 - 1/23
I want to do a chart based on the content of those sheets. Is there any way I can make a formula and extract the name of the sheet from a content of a cell?
For example something like "=EVAL(A1)!$B$4", then I would have the content from "1/12 - 1/16"!$B$4 instead of having to go through each one of the weeks of the year manually.
Thanks for the help!
There’s no need to use AppScript, INDIRECT is enough to read a sheet name from a cell:
=INDIRECT(A1 & "!$B$4")
However, it looks like Andy’s answer is the way to go if you want to get the sheet name from its index rather than from a cell.
It'd be best to use AppScript. In Tools -> Script Editor make a new AppScript script:
function getSheetName(i) {
var s = SpreadsheetApp.getActiveSpreadsheet().getSheets()
return s[i].getName();
}
With that in your script, you can then use the custom function =getSheetName(<SHEETNUMBER>) and it will retrieve the sheet name based what sheet number it is (starting from 0). From there, just incorporate it into your formulas. You may need to use INDIRECT.
Example: =INDIRECT(getSheetName(1)&"!A1") to get cell A1 in the second sheet.