Last active
August 5, 2024 21:34
-
-
Save al-codaio/17a427e27077c3921695c793ad1a0440 to your computer and use it in GitHub Desktop.
Fill cell value down until a new cell value occurs - Google Apps Script for Google Sheets
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
// Google Apps Script to take a value in column A and fill it down until a new value shows up in a cell for Google Sheets | |
// Author: Al Chen ([email protected]) | |
// Last Updated: September 6th, 2020 | |
// Video tutorial: https://youtu.be/t-32QkyjKVE?t=106 | |
function fillValuesDown() { | |
var spreadsheet = SpreadsheetApp.getActive() | |
var currentRange = spreadsheet.getRange("A2:A" + spreadsheet.getLastRow()) | |
var newRange = [] | |
var newFillValue | |
currentRange.getValues().map(function(value) { | |
if (value[0] !== '') { | |
newFillValue = value[0] | |
newRange.push([newFillValue]) | |
} else { | |
newRange.push([newFillValue]) | |
} | |
}) | |
currentRange.setValues(newRange) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could have to change up the
if
statement starting in row 12. You'll have to figure out a way to tell the script when to stop because it will just continue filling empty cells until the bottom of the sheet.