0

I didn't get very far with my previous attempt to get this question answered - maybe I didn't phrase it very well!

If I open an Apps Script spreadsheet and click on the line number, the whole line is highlighted.

If I then right-click and choose "Get link to this range", I get a reference that looks something like "https://docs.google.com/spreadsheets/d/1i2ndEJK...Hcd56/edit#gid=172285634&range=123:123" copied to the clipboard. This clearly identifies both the sheet I have clicked on and the range I have selected.

I want to use this information in my script to access data on the line that I have highlighted. But I can't find a way to do it!

Help appreciated - thanks.

Current code:

function cancelBooking() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
Logger.log('Spreadsheet: ' + ss.getName());
var sheet = SpreadsheetApp.setActiveSheet(ss.getSheets()[1]);
Logger.log('Sheet: ' + sheet.getName());
var range = sheet.getActiveRange();
Logger.log('Range: ' + range.getRow());
var selection = sheet.getSelection();
Logger.log('Current Cell: ' + 
selection.getCurrentCell().getA1Notation());
Logger.log('Active Range: ' + 
selection.getActiveRange().getA1Notation());
}

and the results of the above are:

Spreadsheet: Booking Request (Responses) [correct] Sheet: Booking Database [correct] Range: 1 [incorrect] Current Cell: A1 [incorrect] Active Range: A1 [incorrect]

The cells I actually have selected in the sheet are all those on row 22.

PhilTilson
  • 55
  • 5
  • It's not clear to me what you are trying to do with your code. – Cooper Oct 23 '21 at 18:49
  • How are you calling `cancelBooking`? Change `var sheet = SpreadsheetApp.setActiveSheet(ss.getSheets()[1]);` to `var sheet = ss.getActiveSheet()` – TheMaster Oct 23 '21 at 20:21

0 Answers0