How do you select an adjacent cell from the active cell?

1,129 views
Skip to first unread message

burtran...@gmail.com

unread,
Jun 17, 2021, 12:59:23 PM6/17/21
to Google Apps Script Community
Short on syntax...

burtran...@gmail.com

unread,
Jun 17, 2021, 1:01:33 PM6/17/21
to Google Apps Script Community
More specifically in my instance, the cell in an adjacent column...

On Thursday, June 17, 2021 at 9:59:23 AM UTC-7 burtran...@gmail.com wrote:
Short on syntax...

burtran...@gmail.com

unread,
Jun 17, 2021, 1:07:20 PM6/17/21
to Google Apps Script Community
Is it really just...

const adjacent = column + 1;   ???

Marcos Gomes

unread,
Jun 17, 2021, 1:10:49 PM6/17/21
to google-apps-sc...@googlegroups.com

activeSheet.getRange(ActiveRow, ActiveColumn + 1)


--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/33f3712c-2023-41dc-ba3a-31e1ee5b370dn%40googlegroups.com.

Burt Paulie

unread,
Jun 17, 2021, 2:21:50 PM6/17/21
to google-apps-sc...@googlegroups.com

Burt Paulie

unread,
Jun 17, 2021, 2:28:46 PM6/17/21
to google-apps-sc...@googlegroups.com
Sorry to fuss, but I don't see ActiveRow or ActiveColumn in the GAS ref docs or online. Where do they come from again?


Pipe long and aerogate,
Burt Paulie



Burt Paulie

unread,
Jun 17, 2021, 3:06:28 PM6/17/21
to google-apps-sc...@googlegroups.com
Sorry. I didn't mean to be so lazy about this, despite how trivial it is. Here's what I have. I'm trying to access an adjacent cell in a row and I've never done that before. Could you be more specific?

function getSheet() {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const sheet = ss.getActiveSheet();
  const cell = sheet.getCurrentCell();
  const bool = cell.getBooleanCondition();
  const counter = cell.getRow()
}
 
Pipe long and aerogate,
Burt Paulie



Marcos Gomes

unread,
Jun 17, 2021, 3:15:54 PM6/17/21
to google-apps-sc...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.

burtran...@gmail.com

unread,
Jun 17, 2021, 3:18:33 PM6/17/21
to Google Apps Script Community
I can't. According to the docs ActiveRow and ActiveColumn are not valid syntax. 

Marcos Gomes

unread,
Jun 17, 2021, 4:08:32 PM6/17/21
to google-apps-sc...@googlegroups.com

function onEdit(e) {

  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const sheet = ss.getActiveSheet();
  const range = sheet.getActiveRange();

  const activeRow = range.getRow();
  const activeColumn = range.getColumn();

  //get adjacent cell in rigth column
  const adjCell = sheet.getRange(activeRow, activeColumn + 1).getA1Notation()

  console.log("activeRow: " + activeRow);
  console.log("activeColumn: " + activeColumn);
  console.log("Cell: " + adjCell);

  //view direct in browser
  Browser.msgBox("activeRow: " + activeRow + "\\n" + "activeColumn: " + activeColumn + "\\n" + "Cell: " + adjCell);
}


Burt Paulie

unread,
Jun 17, 2021, 4:18:34 PM6/17/21
to google-apps-sc...@googlegroups.com

Phillip Bainbridge

unread,
Jun 18, 2021, 5:50:44 AM6/18/21
to Google Apps Script Community
Hi

As always in life - there is more than one way of doing this - you could use 'offset' as an alternative. I had a play around with this myself:

Kind regards
Phil
Reply all
Reply to author
Forward
0 new messages