我想多次重复项目范围(提供值)。
例如
我在 sheet1!A
中有此文件Detroit
Texas
Utah
California
现在,我想将它们重复3次以在 Sheet2!A 上获得输出,例如:
Detroit
Texas
Utah
California
Detroit
Texas
Utah
California
Detroit
Texas
Utah
California
公式应该是什么?
我得到了这个公式:
https://www.excel-bytes.com/how-to-repeat-a-range-of-items-multiple-times-in-excel/
但是它不能在Google表格中使用
答案 0 :(得分:0)
仅当将其粘贴到同一张纸的 A5 并将其向下拖动时,此方法才有效:
=IF(ISBLANK(INDIRECT(ROW(A1))),INDIRECT((ROWS($A$1:A4)-(COUNTA(A:A)-2))),A1)
否则,您可以使用:
=QUERY({Sheet1!A1:A4;Sheet1!A1:A4;Sheet1!A1:A4},"select *",0)
或:
=TRANSPOSE(SPLIT(REPT(JOIN(",",Sheet1!A1,Sheet1!A2,Sheet1!A3,Sheet1!A4&","),3),",",1))
或:
=TRANSPOSE(SPLIT(REPT(Sheet1!A1&","&Sheet1!A2&","&Sheet1!A3&","&Sheet1!A4&",",3),",",1))
或:
function REPEAT(range,amount,header) {
var output = [];
// check if range is cell
if(typeof range == 'string') {
for(var i=0; i<amount; i++) {
output.push([range]);
}
return output;
} else {
// check if header is wanted
var value;
if(header == 1) {
output.push(range[0]);
value=header;
} else if(header == "") {
value=0;
} else {
value=0;
}
for(var i=0; i<amount; i++) {
for(var j=value, jLen=range.length; j<jLen; j++) {
output.push(range[j]);
}
}
return output;
}
}
=REPEAT(Sheet1!A1:A4,3,0)
答案 1 :(得分:0)
我也可以将其添加为答案:
=IF(ISBLANK(INDIRECT("Cities!A"&ROW(A2))),INDIRECT("Repeat!A"&(ROWS($A$2:A2)-(COUNTA(Cities!A:A)-2))),Cities!A2)
在Google表格和Excel中工作正常。
这也可行,并且在Excel中最好避免使用Indirect:
=IF(ISBLANK(INDEX(Cities!A:A,ROW(A2))),INDEX(Repeat!A:A,ROWS($A$2:A2)-(COUNTA(Cities!A:A)-2)),Cities!A2)
答案 2 :(得分:0)
您可以从第1行复制下来:
=offset(Sheet1!A$1,mod(row()-1,4),)
适合您的四件套。