1

In my spreadsheet I have a trivial script, which is adding a new row and getting the cursor into the second cell of the new row:

function rowadd() {
  var d_akt = SpreadsheetApp.getActive();
  var a_akt = d_akt.getActiveSheet();
  var w_akt = a_akt.getActiveRange().getRow();
  a_akt.insertRowsBefore(w_akt, 1);
  a_akt.setActiveRange(a_akt.getRange(w_akt, 2));
}

The script runs when a user presses a button in the sheet. Works almost fine, but after the script ends the cursor is in the right cell, but i cant write in that cell without a mouse click. Looks like the navigation is not in the sheet. Can't find any solution how to fix that issue.

Rubén
  • 34,714
  • 9
  • 70
  • 166
maruda
  • 13
  • 2
  • It works for me. I can add text without clicking the mouse. – Cooper Oct 05 '17 at 23:06
  • I tried on Chrome and Firefox and nothing. [link](https://drive.google.com/open?id=11jOvu1BrbX3xEFrTX3RSL8VnG21wZsgz0cFGL67yZfI) When i click the button i get a new row, but I have to click in it to write something. – maruda Oct 06 '17 at 06:43
  • I suppose one difference is that I created a menu item because I don ‘t use buttons in sheets. That may change the focus. – Cooper Oct 06 '17 at 09:40
  • @Cooper - thanks for your response. What do you mean by "menu item". Im not sure if I understand that correctly. Found a similar problem here: [link](https://stackoverflow.com/questions/30897408/google-sheets-script-range-activate-still-requires-user-to-click-in-order-to) – maruda Oct 06 '17 at 10:54

1 Answers1

0

You can create a menu of your own like this:

function onOpen()
{
   SpreadsheetApp.getUi().createMenu('My Menu').addItem('Description','functionName').addToUi();
}

We typically put it in a simple trigger onOpen() function so that it runs whenever you open the file. You can learn more about it here.

Another option is to create a sidebar dialog and put buttons there. That's a little more effort but the pay of is that you don't have to open up a drop down menu. You can just click on a button immediately.

Cooper
  • 59,616
  • 6
  • 23
  • 54