The code starts by getting the current active spreadsheet and sheet (so this will vary depending on where you are clicked when you run the function - rather than specifying an exact sheet to access). From here the 'activeCell' is acquired (so where the cursor is clicked on the sheet), then the value ('getValue') of that cell is captured in a variable and logged for reference. Finally it looks for the row number ('getRow') of the current cell and logs that too.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getActiveCell() { | |
// get the active spreadsheet and sheet | |
var ss = SpreadsheetApp.getActiveSpreadsheet(); // ss contains entire spreadsheet | |
var sheet = ss.getActiveSheet(); // sheet contains current active sheet ('Students') | |
// from sheet, get active cell and store as variable | |
var activeCell = sheet.getActiveCell(); | |
// from activeCell, get value and store as variable | |
var cellValue = activeCell.getValue(); | |
// show value of cellValue | |
Logger.log(cellValue); | |
// from activeCell, also show row number | |
var cellRow = activeCell.getRow(); | |
Logger.log(cellRow); | |
} |
This helped me. Thanks for posting.
ReplyDeleteYou're very welcome!
Delete