0

I noticed recently that buttons created in the google worksheet don't work on mobile. I found the resolution, however now I wonder how could I point the code presented in the article to the specific tab in my worksheet, for instance, "sheet 1" and "sheet 2". As I'd like the code to work on both tabs "sheet 1" and "sheet 2", in parallel. So that two different users, can work on two different tabs at the same time.

Would anyone know how to overcome this issue?

https://medium.com/macadamscripts/create-button-in-google-sheets-mobile-2979579025ef#:~:text=Luckily%2C%20there%20is%20a%20workaround,serve%20as%20the%20%E2%80%9Cbutton%E2%80%9D

function onEdit(e) {
if (e.range.getA1Notation() == 'D4') {
if (/^\w+$/.test(e.value)) { 
eval(e.value)();
e.range.clear();
   }
  }
}

Best, D

Ducatia
  • 31
  • 2
  • 8
  • 1
    I cannot understand about `I point the code presented in the article to the specific tab in my worksheet, for instance, "sheet 1" and "sheet 2"`. I apologize for this. Can I ask you about the detail of your goal? – Tanaike Feb 24 '21 at 00:26
  • 1
    Possible duplicate [button click is only working on Windows & not working on Android mobile sheet](https://stackoverflow.com/q/57840757/1595451) – Rubén Feb 24 '21 at 05:56
  • Hi Ruben, thank you for pointing out the sibling post. I've checked the code and it's working fine. The only problem I have now is how to make the function onEdit (e) work on two different tabs "Sheet1" and "Sheet2" if we already figured out the way to point it to the specific tab name. function onEdit(e){ if (e.range.getA1Notation() == 'D4' && e.range.getSheet().getName() === "Sheet 1") { if (/^\w+$/.test(e.value)) { eval(e.value)(); e.range.clear(); } } } – Ducatia Feb 25 '21 at 10:18

2 Answers2

0

Try to use activeSheet.getName in handling/checking a specific sheet on your spreadsheet. See sample code below on how to achieve it:

function onEdit(e) {
  //Set a comment on the edited cell to indicate when it is changing.
  var range = e.range;

  var activeSheet = e.source.getActiveSheet();
  if (activeSheet.getName() == "Sheet1") { //Sheet1 is just a sample name of the sheet. Modify it according to the name of your sheet.
     range.setNote("Last Modified:" + new Date());
  }
}

Reference:

use onedit() trigger on a specific sheet within google scripts for google sheets

Monique G.
  • 239
  • 1
  • 6
  • Monique G. thank you for sharing the answer! The only issue here is that I'd like to keep the functionality that only when a specific cell number ( for instance D4 ) on the specific sheet (Sheet1) is going to change, that trigger the action on mobile. On the desktop, I have no issue with this as I'm using buttons :/. Would you know how to overcome this? Best, D – Ducatia Feb 24 '21 at 09:57
0

Just for anyone else who may read this, Google defines:

Spreadsheet = the actual Sheet Document containing the sub sheets.

Sheet = the "tabs" as Ducatia uses.

Anyway, to answer the question, you could try using this which will set the tab to whatever is specified. You can select a sheet based on index of the array but sheet orders can be moved and unfortunately names can be changed too, but not accidentally like simple sheet reorder, so just need to be careful. You can get the sheet's ID but I can't see a way to select a sheet by ID. If I do I'll update this.

I used something like this:

  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName("TEST"));

If you run the above, with a proper name, you can watch your spreadsheet change the UI view to the specified sheet.