1
votes

How can I individually step through a range of cells in Google Sheets? I have a range of several cells (eg. D2:D10) and need to step through each cell in the range to pass to a function. The function accepts only a range of one cell (eg. D5) and performs an offset to change the background of a nearby cell.

My thought was to parse through the range in a for loop and send each cell to the function, but I can't seem to find a way to index within a range to pull out a subset. What am I missing?

I don't care about the values in the cells, so creating an array out of the values does not help me.

Thanks!

1

1 Answers

2
votes

Use the getCell(row, column) function - it returns a cell (1-based) relative to the range. You can combine it with getNumRows() and getNumColumns() to parse over the range.

https://developers.google.com/apps-script/reference/spreadsheet/range#getCell(Integer,Integer)