0

I have a simple macro in Google Sheets that I can run from Tools > Macros > MacroName. I have it set up with a trigger to run when the spreadsheet is first opened. (All the macro does is go to the first empty cell in column A, from https://webapps.stackexchange.com/a/101200)

However, what I would really like to do is to have this macro run every/any time the active sheet is changed in my spreadsheet. So when I click on a sheet's tab at the bottom of the screen to open a different sheet (in the same google sheets spreadsheet file), the macro runs. If I change back to the previous worksheet tab the macro runs, etc.

In Excel there's a function Worksheet.Activate which I believe would do what I want there, but I can't find a matching function in Google Sheets.

How can I get a macro to run when the active sheet changes? (Only within the one spreadsheet)

1

See Tanaike's gist "Change Tab Detection on Google Spreadsheet using onSelectionChange Event Trigger with Google Apps Script".

You may also want to take a look at the jumpToToday_ script which would probably be an easier way to quickly go to the spots of recent interest in each sheet of your spreadsheet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.