Checks if a range is a cell [snippet]

35 views
Skip to first unread message

Alex

unread,
Mar 18, 2020, 3:30:11 AM3/18/20
to google-apps-sc...@googlegroups.com
Is there the best way for check if the range is a cell?

/**
 * Checks if a range is a cell
 * @param {GoogleAppsScript.Spreadsheet.Range} range
 * @return {boolean}
 */

function isRangeACell_(range) {
 
return !/:/.test(range.getA1Notation());
}


https://github.com/contributorpw/google-apps-script-snippets/blob/master/snippets/sheets/is_range_a_cell/code.js#L8

Best, Alex.

Alan Wells

unread,
Mar 18, 2020, 8:52:34 AM3/18/20
to Google Apps Script Community
I think you found the best way.

Steve Webster

unread,
Mar 18, 2020, 9:40:08 AM3/18/20
to google-apps-sc...@googlegroups.com
I like yours. 
Other option is if e.range.getNumRows() or e.range.getNumColumns() is greater than 1.

Kind Regards,

Steve Webster
SW gApps LLC, President 
Google Product Expert in: Google Apps Script, Drive, and Docs 
Google Vendor (2012-2013) || Google Apps Developer Blog Guest Blogger 
Add-ons: Text gBlaster and Remove Blank Rows


--
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/1127e7ee-c29c-405c-8413-149fec13e3ad%40googlegroups.com.

Alex

unread,
Mar 20, 2020, 4:43:16 AM3/20/20
to Google Apps Script Community
Thanks @Alan @Steve

For more authentic I gave up RegEx

function isRangeACell_(range) {
 
return !~range.getA1Notation().indexOf(':');
}

Alan Wells

unread,
Mar 20, 2020, 8:44:38 AM3/20/20
to Google Apps Script Community
You are very wise (in Bits)
Reply all
Reply to author
Forward
0 new messages