Selecting/highlighting next adjacent cell in row after function has been executed in google script - google-apps-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

Related

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

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.

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.

Linking one cell to another in a spreadsheet

I have a dynamically generated spreadsheet. I would like to be able to allow the viewer to go to a different sheet/cell when a cell is clicked on. I'm having trouble figuring out a good way to do this.
Going to the new cell is fairly easy: Spreadhseet.setActiveSheet()/Spreadsheet.setActiveRange() work fine. My thought was to encode the link destination in the contents of the source cell, and then write a script to "follow" the link.
I tried using images or drawings. But there were two problems with this: while images can be inserted programmatically, I did not see a way to programmatically associate a script with them. And the called script does not have an associated event tied to it, so there is no way to see what cell the user clicked (clicking an image does not set the active cell).
I thought about using onEdit(). This almost works, but onEdit is only triggered on changes (not selection) so the user actually has to modify the cell in order to "link". When testing I tended to zap the contents of the cell by accident with onEdit.
I tried making a menu item, and in the menu's script get the active cell's contents to determine where to go to. This worked but was a bit more difficult for the user than I was hoping for.
I was hoping someone would have a creative solution to this problem.
Thanks!
From what you are describing the drawing or image insertion should work since it has exactly the same functionality as the menu item. You can assign a script to it just like in a menu.

Re-naming chart legend in Access 2007

In an auto-generated chart based on a query (I dragged the chart object onto a blank form to start it), the chart itself is displaying and updating properly, datawise, but I want to change the Legend from reading "SumOfAvgOfield1" and "SumOfAvgOfield2" to regular words suitable for final presentations. But I can't find a way to change it!
I realize this is a late answer, but I was just having a similar issue and figured someone else might benefit from knowing how to get rid of the 'SumOf' labels.
In design view, right click on the chart and select 'Properties'.
Choose the Data tab.
The 'Row Source' field is the one you're going to be interested.
In there you can see various places where it's labeling your data:
Sum() AS [SumOfData]
Just edit the text right in the properties window and you'll be set.
This is WAY late, but here's what I found (Yes we still use office 2007)
Open the form in PivotTable View. Open Property Sheet. Highlight the column you want to change the Legend Caption for. Choose the Captions Tab in the properties window. There you can change the captions for each column.
Had 4 charts on a form. 3 would let me edit the Heading of the Chart, the 4th would not. Read a lot of posts that did not pertain. Noticed the datasheet for the 4th chart was completely empty.
SOLUTION: Clicked on chart until the datasheet appeared. Added mock field headings and mock data to datasheet. I could then click on chart and edit the chart's Heading. You can also highlight and change the color of selected words in the chart's Heading. Very Nice!
Good luck,
Vancer
The SumofAverageOfFiled1, etc is automatically generated. Even if you edit it in the datasheet, it changes back (or at least that is my experience). What I did to get around this is add a Rectangle and fill it with white and size it to cover up the "Sumof" captions. You can Bring to Front the Rectangle. Then you can add text boxes to label the chart's bars to read the way you want them. Drag them over the Rectange and Bring to Front.
Hope this helps.
Everywhere I looked it said just change the Pivot Table to change the Legend Entry.
Well, let me tell you.
First, if you have no Pivot Table that you can see do the following:
go to design view and select the form
right click and hit Properties. Scroll through till you see AllowPivotTableView and select yes.
Now you can go and change the column headers!
This could help
Select xxxxx, yyyyy from zzzz
Chart0.ChartSeriesCollection(0).DisplayName = ![XXXXX]
Chart0.ChartSeriesCollection(1).DisplayName = ![YYYYY]
Was very difficult to me to find a way to do it.

Rendering 20 large identical listBoxes

I have an HTML table with rows (20 rows).
Every row has a listbox of countries (about 250 countries) that are filled using a single dataset from the database.
Loading time is quick enough, but rendering time is really a mess.
Is there any way I can speed the rendering of those listboxes?
You could load it only once, and then copy the DOM element everywhere you need it...
I'm not sure if this would improve a lot since it would rely more on the user's computer, but I guess it's worth trying if it's too slow the way it is right now.
edit: here's how I'd do it. Use with caution, I haven't tested it and there is most likely tons of errors with this code, it's just to give you an idea of what I was saying.
<mylistbox id="listboxtemplate"> ... </>
<div class="thisPlaceNeedsAListbox"></div>
<div class="thisPlaceNeedsAListbox"></div>
<div class="thisPlaceNeedsAListbox"></div>
on document ready, using jquery:
jQuery(".thisPlaceNeedsAListbox").append( jQuery("#listboxtemplate").clone() )
You could try to add next select box only after user has selected previous one (using JavaScript).
I'm quite sure that you can rethink the form or the process, but I can't suggest anything specific since you haven't given enough information. For example depending on situation you could use multi-select or some fancy JavaScript widget.
EDIT based on your comment:
Then how about serving the table without selects. And if user double clicks on a country field you change the text element to select element using javascript. And once user has selected the country you can change back to text element. You can submit results back to server using Ajax (after user has selected the country) or using hidden fields a submit button. This way DOM will never contain more then 1 select element.
You can pass countries to javascript using inline JSON object/array (in script tags). To make things even more faster after user has edited the first element, just hide (css: display: none;) the first build select element and clone/move it around each time user wants to edit a row.
As you can see there are a lot of paths you can take using this approach, it all depends how much you want to optimize/work on it.