How to get the value of a cell relative to its position, and not written independently? (Similar to ActiveCell.Offset.Value from VBA)
|
1 answer
Analog in GAS is the Range method - offset (rowOffset, columnOffset)
Example of use (taken from the same place):
function testOffset(){ var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; var cell = sheet.getRange("A1"); // newCell references B2 var newCell = cell.offset(1, 1); } PS If you need to get the value of the cell, then use the methods of the Range object:
- And if this is a user-defined function and I need the offset to be relative to the cell in which it is written? With that, I donβt know in advance which cell it will be recorded in (or rather, the recording location is dynamic) - Age of Creations
- This function is the offset relative to another cell. - Sergey Pryanichkin
- I understood this, and I ask that if I need an offset not relative to a known cell, but relative to a cell into which a user function is written, despite the fact that it is unknown in advance. - Age of Creations
- The current cell can be obtained using getActiveRange () or getActiveCell () - Sergey Pryanichkin
- one@ age-of-creations your mistake is comparing VBA and Google Apps Script. Do not do this because there is nothing to compare. User function does not know the position where it is running. She needs to pass these parameters. - oshliaer
|