I am using the following code to get selected cells:
var activeRange = SpreadsheetApp.getActiveRange().getA1Notation();
If I select cells B1, B2, B3 it returns "B1:B3". But if I select B1 and then use the Ctrl key to also select B3 it returns only "B3". I want "B1,B3". I couldn't find a function for this in the documentation.
Equality (==): a == b results in true if the value a is equal to value b. Strict equality (===): a === b results in true if the value a is equal to value b and their types are also the same. Inequality (! =): a !=
Get selected cell value in your Google Sheet Script Now we have to add getCurrentCellValue() function. This function will get the value of the currently selected cell and then show it in a message box. In order to make it a little more informative, let us show the cell's A1 notation and then its value.
Using keyboard shortcuts, To select an entire column press Ctrl + Space . To select an entire row, press Shift + Space .
Type = followed by the sheet name, an exclamation mark and the cell being copied. For example, =Sheet1! A1 or ='Sheet number two'! B4 .
var range = '';
var sel = SpreadsheetApp.getActive().getSelection().getActiveRangeList().getRanges();
for(var i = 0; i < sel.length; i++){
range += sel[i].getA1Notation() + ', ';
}
Logger.log(range);
Logs: [18-06-21 22:18:16:866 EEST] B1, B3,
Apps Script currently does not provide support for handling disjoint ranges within Range objects. What will happen is that the last selected sub-range will be returned by calls of getActiveRange(), etc. It is filed here as issue 4069. You may want to 'star' it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With