Created
October 16, 2019 17:02
-
-
Save chulman444/f9d0c93f37421b56137c1072e3b6a62f to your computer and use it in GitHub Desktop.
Google sheet script for iterating over range list of a selection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function iterateSelection() { | |
var selection = SpreadsheetApp.getSelection() | |
var rangeList = selection.getActiveRangeList() | |
var ranges = rangeList.getRanges() | |
var count = 0 | |
var anchor_pos = [10, 1] | |
SpreadsheetApp.getActiveSheet().getRange(anchor_pos[0] - 1, anchor_pos[1]).setValue(ranges.length) | |
for(var i = 0; i < ranges.length; i++) { | |
SpreadsheetApp.getActiveSheet().getRange(anchor_pos[0] + i, anchor_pos[1]).setValue(ranges[i].getA1Notation()) | |
var num_rows = ranges[i].getNumRows() | |
var num_cols = ranges[i].getNumColumns() | |
SpreadsheetApp.getActiveSheet().getRange(anchor_pos[0] + i, anchor_pos[1] + 1).setValue("(" + num_rows + ", " + num_cols + ")") | |
var count = 0; | |
for(var j = 1; j <= num_rows; j++) { | |
for(var k = 1; k <= num_cols; k++) { | |
SpreadsheetApp.getActiveSheet().getRange(anchor_pos[0] + i, anchor_pos[1] + 2 + count).setValue(.getValue()) | |
count ++ | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment