Is there any way to make it so that a cell can only be changed once in Google Sheets? - google-apps-script

I have a Sheet which I would like to use as a simultaneous sign up for many people for timeslots for an event. We have noticed that what can happen is users erasing each other's entries in the sheet. Ideally we would like to make it so once someones name is entered for a timeslot it cannot be removed by other users.
I've tried to use data validation to reject certain criteria, but I've only managed to get it to reject a cell changing from blank to a non-blank value. Which I achieved with the following:enter image description here. But I'd like the opposite behaviour, with some additional functionality
Changing the formula to NOT(ISBLANK(B2)) doesn't seem to put any restriction on the cell at all as hitting backspace or delete on cell seems to clear the contents without ever considering that an input to check. Changing the value never causes the cell to go blank so it doesn't seem to affect changing either. I'm really at a loss as to how to do this and any help is appreciated. I'm open to solutions which use VBA or other programming languages to get the desired result as well.

Related

Edit cell above cell that called a function?

I'm using Google Apps Script to make a function that will be called in a Google Sheet. The function does some auto calculating for a spell effect. Some spells need the player to provide extra info (How many people are you shielding, etc) and some don't need any additional inputs. If extra info is needed, the user provides it in the cell directly above the cell that calls the function. I'll call this the "input cell" for clarity. The "function cell" is the one that calls the function, directly below the input cell.
My question is this: if the extra info is unneeded, as determined by conditionals within the function, how do I overwrite the contents of the input cell with '-'? I can't put a formula within that cell directly, because the user would overwrite the formula when entering the additional information. The function also returns a value to the cell that called it.
I've tried a bunch of techniques but I can't figure out how to do it.
I tried returning an array of both values, but it flows downwards instead
of upwards, and I couldn't find anything for "return array offset
upwards" or something to that effect.
I can't use absolute references
like "L17" because the function can be called from many places on the
sheet, and it also only needs to mess with the cell directly above it.
using setValue() or setValues() threw a "no permission" error.
I would attach my code, but it's a mess of half-deleted attempts that didn't work, and wouldn't be much help at all. I also don't want to ask anything too specific, for fear of running into the https://xyproblem.info problem. I just want to be able to have a function edit the cell directly above it, and I don't care about which technique gets that accomplished.
Any help is greatly appreciated. Thank you!
No cell can contain both a formula(or a output of a formula) and simultaneously contain a user entered value. That was always the case with any spreadsheet, Excel or Google sheets or any other. It's one or the other. Choose one and redraw your logic!
For your specific problem, if you can reflow your logic, you might try simple triggers like onEdit.

Google Sheets - Track Current Cell Selection?

How to Get the currently selected cell/range? was asked 3.5 years ago, but I'm hoping maybe some progress was made since then.
I'd like to make an interactive spreadsheet where there's a boolean grid that will display more information about the status of the currently selected cell in a static location, allowing users to quickly navigate using the arrow keys.
Referencing the previous instance of this question, I tried using the custom function below to get the cell address, although this isn't very dynamic.
function currentCell() {
return SpreadsheetApp.getActive().getActiveRange().getA1Notation();
}
When testing, this function returns the address of the cell the function is called from. I've tried pressing F5 while highlighting another cell and nothing happened. I've also dragged the formula across a selection and each cell only contains its own address (according to the documentation, it should contain the range).
I've also read Henrique's post on caching from 2012, and while I don't completely understand it, I get that we could not get scripts which update without edits being made or manual formula updates.
I would ideally like for the current cell to be tracked without any extra prompts from the user besides arrow key navigation or clicking to select a cell, but if pressing a non-altering key (like Enter) would allow for tracking, that would be fine. I also only need the selected cell, rather than a range, if that makes things easier.
Explicit Question: Is it possible to track the position of the currently selected cell in Google Sheets and store that position in a separate cell? If not, is there a way to do this without altering cell values?
EDIT: Adding an example for clarity. In this conceptual example, A2 =currentCell() as described above. If I were to hit the right arrow key, A2 would update to display I4, since it is now the current selection.
EDIT2: Jason Allshorn's response to Google app script monitor spreadsheet selected ranges appears to give a way of displaying the current selection (range) on the HTML input text. I'd like to do this, but store the value in a static cell on the sheet rather than input text. I'm new to scripting in Sheets and really only know what I've found for resolving this issue, so if I'm overlooking something, please let me know. I did look at Jason's example sheet and it wasn't clear to me what was actually happening there.
You will have to apply the technique suggested on How do I make a Sidebar display values from cells?. This consist on using using client-side code to constantly pulling values from the spreadsheet and then do the corresponding task.
One approach is to use a side-panel with an input field to set the cells to be tracked and another input field to set the destination cell.
You will have to use the onSelectionChange event in the app script to capture any selection change and then get the range name and put it in desired cell.
Something like the below:
function onSelectionChange(e) {
const range = e.range;
//Return in case of multi cell selection
if(range.getNumRows() !== 1 || range.getNumColumns() !== 1) return;
SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange("A2").setValue(range.getA1Notation());
}
You can see the official documentation here

Selecting/highlighting next adjacent cell in row after function has been executed in google script

I am not really experienced with coding so I apologize in advance if this is a stupid question with an obvious answer...
I use a google sheet to keep track of things at work, and my employees use it multiple times a day. They will either type one of three phrases into a certain cell on a row, so I have created buttons using the drawing feature that they can simply click, which will insert the appropriate text into the highlighted cell.
Once this text is inserted into the cell, I would like to add something to the end of the function that automatically selects the next adjacent cell in the row (to the right) so they can continue typing in. Currently, once they click the button to insert text into one cell (e.g., B23) they have to use the mouse to manually select C23 before typing into that cell. For some reason you cannot use the right arrow key or tab key on the keyboard to move over, so I am wondering if there is a way to add the selecting process into the script (or even a workaround for allowing the tab or right arrow keys to work).
I realize this may seem like a tedious question and folks may think it is awfully lazy of me to ask for a more efficient way to move over to a cell than using the mouse, but my employees use the sheet hundreds of times a day, so I'd really like to maximize the efficiency for them to make it as easy and convenient as possible. Inputting data can be tedious enough, so I am trying to simplify things and make it as least painful as possible :)
Thanks so much!
There are several ways to select the cell at the right. One way is to use offset(rowOffset,columnOffset):
range.offset(0,1)
You are correct. When using a button the focus stays in the button when it is clicked. After some trial and error, I think I found a way that will work fot you. I created a html sidebar that is opened from a custom menu. Once opened, you can leave it opened, HTML allows control over the focus using 'google.script.host.editor.focus()'. Then you can type in the cell. Attached is my sample spreadsheet you can copy and try. Let me know if you need any help changing the button names or text. Sorry my first try didn't work correctly. https://docs.google.com/spreadsheets/d/1KlNSJnZDNIb2chUK3SlKJg79VNIrsAbIbUvHyLwTLWk/edit?usp=sharing

Google scripts unhideRows not working

I have a script for Google Sheets I am working on. I realize there are better ways to do what I am attempting (cough html/database cough), but I am required to make this spreadsheet work.
In short, I am trying to hide and unhide rows dynamically. There does not appear to be a way to get filters to update without redoing them, so I am attempting to use hideRows to hide them and unhideRows to reveal them as needed.
The hideRows command works below. The unhideRows command does not. At this time, they are literally this close together in the code. Originally, I was hiding on one sheet and unhiding on another, but set up like this to troubleshoot. There is no filtering on this sheet (because it didn't work, I turned it off). I tried setting the value in unhideRows directly to the value tested instead of a variable.
The row in question hides, but does not unhide.
I tried unhiding a different row just in case google was fumbling with hide this, unhide it back to back. I am not getting unhide to work.
{ //thisRow = the row number of a range, in this case 2 if output to screen
pImages.hideRows(thisRow);
pImages.unhideRows(thisRow);
}
Apparently, the answer is not to unhideRows() which is the one the documents alluded to, but showRows () which does make more sense in everyday language. Thanks again to Mr.Houdini on the Google forums.

Google Spreadsheet: Script to Change One Cell's Background Color when Another Cell Changes Text

I have a Google spreadsheet where I keep a list of tasks, and I constantly change the status from four variations. For the purpose of this questions lets just say the four statuses are "Done", "Not Done", "In progress", "Failed".
I want to write a script for the Google spreadsheet where when I change the status, the cell right next to it will display a specific color respective to the status of each task.
I have looked into a few of the previous example where they highlight the whole row, but I'm looking into how to highlight one specific cell.
This can be accomplished with conditional formatting directly in the spreadsheet.
Right click on the first cell you want to change the color and choose "Conditional Formatting"
In the drop-down choose Custom formula is... Then enter =(A2 = "Done"). Check background color select then select a color. The range should be auto filled.
A2 would be whatever your status cell is.
Repeat this for each status you have.
You then can "Highlight and Drag-Copy" the cell with the formatting and it will adjust the range for you.
I'm new here, so please forgive any breaches in forum etiquette, but another user posted a similar question recently, and user Zwisch answered it using a loop that I think might also be applicable to what you are trying to accomplish.
You can likely adapt his answer to your needs by adding another conditional statement to address your different statuses. I do not yet have enough expertise to provide you an exact adaptation however.
See Zwisch's answer to how to apply conditional formatting using code.