Created
April 1, 2022 13:45
-
-
Save phillypb/663d43a970d74c8daf896f67f48af428 to your computer and use it in GitHub Desktop.
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
/** * @OnlyCurrentDoc */ | |
function autofill() { | |
// get active sheet | |
var sheet = SpreadsheetApp.getActiveSheet(); | |
// get last row of data for later pasting into | |
var lastRow = sheet.getLastRow(); | |
// create Formula for first row | |
var formula = "=Sum(F2+G2)"; | |
// get source range - where Formula will be inserted and autofilled from | |
var sourceRange = sheet.getRange(2, 8); | |
// paste Formula in to first row (ignoring Header row) aka source range | |
sourceRange.setFormula(formula); | |
// get the rest of the range to fill with the Formula (includes source range). Minus 1 for Header row | |
var destinationRange = sheet.getRange(2, 8, lastRow - 1, 1); | |
// insert Formula, continuing the pattern | |
sourceRange.autoFill(destinationRange, SpreadsheetApp.AutoFillSeries.DEFAULT_SERIES); | |
} | |
/* | |
This Function creates a menu item to run this script. | |
*/ | |
function onOpen() { | |
SpreadsheetApp.getUi() | |
.createMenu('Admin') | |
.addItem('Autofill', 'autofill') // label for menu item, name of function to run. | |
.addToUi(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tysm!