[英]AutoFill Data with Blank Rows - Google Sheets / Google Apps Script
I have the below spreadsheet that I would like to AutoFill the persons name.我有下面的电子表格,我想自动填充人名。 the issue is that there are blank rows between the names.
问题是名称之间有空白行。 Each name is in line with a sku2 and needs to be inline with all locations.
每个名称都与一个 sku2 一致,并且需要与所有位置内联。 there can be up to 10 blank rows (due to how many locations).
最多可以有 10 个空白行(取决于位置的数量)。
if I could loop this maybe如果我可以循环这个也许
function LoopTillLr() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('A2').activate();
spreadsheet.getActiveRange().autoFillToNeighbor(SpreadsheetApp.AutoFillSeries.DEFAULT_SERIES);
spreadsheet.getCurrentCell().getNextDataCell(SpreadsheetApp.Direction.DOWN).activate();
};
Appreciate any help感谢任何帮助
If you only want to replicate the NAME values against variable LOCATION values then use this script:如果您只想针对变量 LOCATION 值复制 NAME 值,请使用此脚本:
function myFunction() {
var ss = SpreadsheetApp.getActiveSheet();
var lastRow = ss.getDataRange().getLastRow();
for (var i = 1; i < lastRow+1; i++) {
if (ss.getRange(i,1).getValue() == "") {
var value = ss.getRange(i-1,1).getValue();
ss.getRange(i,1).setValue(value);
}
}
}
Ensure that A2 is not empty else the script will fail.确保 A2 不为空,否则脚本将失败。
If it is a lot of records, you can create a function and run it.如果记录很多,可以创建一个function并运行。 The following does this until the end of the sheet, so make sure to delete all the rows towards the end which you do not need or adjust the range in the 2nd row.
以下内容一直执行到工作表末尾,因此请确保删除不需要的所有行或调整第二行中的范围。
function autoFillDown(){
const range = SpreadsheetApp.getActiveSheet().getRange("A:A");
const rows = range.getValues();
let outputArray = [];
rows.forEach( row => {
// if it contains a name, leave it
if( row[0].length > 1){
outputArray.push( [row[0]] )
// otherwise replace it with the value above it
} else {
outputArray.push( [outputArray[outputArray.length-1]] );
}
});
range.setValues( outputArray );
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.