0

I'm looking for a script that will automatically open a Google Sheet to the last row/first column every time you open the entire worksheet and every time you switch through the sheet tabs.

I've tried copying the following code I found online into Google's Script Editor, but I receive an error:

function onOpen(e) {
  var spreadsheet = e.source;
  var sheet = spreadsheet.getActiveSheet();
  var lastRow = spreadsheet.getLastRow();
  var range = sheet.getRange("A" + lastRow + ":A" + lastRow);
  sheet.setActiveRange(range);
}

TypeError: Cannot read property "source" from undefined. (line 2, file "Code")

Tanaike
  • 181,128
  • 11
  • 97
  • 165
  • In your script, OnOpen trigger is used. So when the Spreadsheet is opened, the last row of column "A" is activated by the event trigger. In the current stage, unfortunately, there is no event trigger by switching tabs yet. And I think that the error is due to running directly the script by the script editor without using the OnOpen event. – Tanaike Mar 27 '19 at 00:18
  • Possible duplicate of https://stackoverflow.com/questions/52632780/scroll-all-worksheets-to-last-row-on-open/52667081 – tehhowch Mar 27 '19 at 00:54
  • @Tanaike - Hmmm. What is interesting is that this particular script has no effect at all on the spreadsheet. To be honest, I'm very out of practice with coding so I'm just finding what other people have and blindly hoping that it'll work with my situation.... :-/ – JoELlekesLY Mar 27 '19 at 20:58
  • @tehhowch - Thank you for the reference. I had already seen this post prior to my inquiry and unfortunately that script didn't work for my spreadsheet either. :( – JoELlekesLY Mar 27 '19 at 21:00
  • 1
    If you had already seen it and found that it did not work, why wouldn't you mention that when you talked about the things you had already tried? That way you prevent people from wasting time suggesting things for you to do, and you attract better attention by demonstrating that you have put work into attempting to solve your issue yourself. https://stackoverflow.com/help/how-to-ask – tehhowch Mar 27 '19 at 21:23
  • @tehhowch - I already reviewed StackOverflow's "How To Ask" guide before submitting my post & I didn't think it was relevant to mention that I had already reviewed Ted Landres' post. I apologize for unintentionally causing you any inconvenience. As I commented earlier to another user, I'm very out of practice & as stated in my question, I'm simply looking to see if anyone can provide me the script that I need for my situation. If you are unable to provide any help, please don't feel obligated to comment on my post - you may move on to assisting other people who may benefit from your expertise. – JoELlekesLY Mar 28 '19 at 17:54
  • Note that when you say "it didn't work" you don't actually describe anything useful. There are infinite reasons why something might "not work" -- error? doesn't do what you want? does what you want, but also extra stuff too? -- hence you must describe the specific issue and the exact problems that occurred, including any error messages. For example, you have never stated how you consume the scripts you have tried here. If you are attempting to run them manually, they will not work and will throw an error. See https://stackoverflow.com/questions/16089041/how-can-i-test-a-trigger-function-in-gas – tehhowch Mar 28 '19 at 18:09

0 Answers0