-
-
Save al-codaio/17a427e27077c3921695c793ad1a0440 to your computer and use it in GitHub Desktop.
// 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) | |
} |
Thank you!!
You're welcome!
Very nice @al-codaio
Is there an easy way to turnaround the functionality? In my sheets I need the value from a lower cell instead of the cell above.
Very nice @al-codaio Is there an easy way to turnaround the functionality? In my sheets I need the value from a lower cell instead of the cell above.
Unfortunately it would require a bit of editing to the loop that goes through all the cells in currentRange
, would love for someone to figure it out!
How would this coding change if you wanted consistent text to be entered into any blank cell as the macro runs?
How would this coding change if you wanted consistent text to be entered into any blank cell as the macro runs?
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.
Thank you!!