is it possible to get a range surrounding a particular cell, similar to Ctrl+A in the spreadsheet?
相关问题
- How can I force all files in a folder to be owned
- Google Apps Script: testing doPost() with cURL
- Google Apps Script to turn in, grade, and return a
- Script fails on SpreadsheetApp.openById - Requires
- Split Lines and Bold Text within a ui.alert Window
相关文章
- How to allow access for importrange function via a
- Google app script trigger not working
- Set Date/Time to 00:00:00
- indexOf returning -1 despite object being in the a
- Using MIN() inside ARRAYFORMULA()
- How can my Google Apps Script be run by others the
- Google Spreadsheet COUNTIF formula equivalent with
- In Google Sheets how to reference infinite rows in
I have a number of spreadsheets where tables are created by
QUERY()
functions, so the boundaries are flexible. In past, I've resorted to setting up named ranges that are the size that I anticipate is the largest that the QUERY results will need, and using those named ranges for other operations.No longer!
Here's a utility function,
getContiguousRange()
that accepts a cell location in A1 notation, and returns theRange
of contiguous cells that contain it. This code is available in a gist.As a test, consider this spreadsheet. It has two contiguous ranges, both with ragged edges.
Here's our test function:
And this is what we get:
I hope that helps!
I tried the above, which I can't comment on due to lack of reputation, in a worksheet with more than one sheet and found it worked better if you change the line: var contiguousRange = SpreadsheetApp.getActiveSheet().getRange(cellA1); with var contiguousRange = sheet.getRange(cellA1);