我正在尝试将公式应用于一列中的每四行:
=SUMPRODUCT('Sheet1'!C$2:C$25;TRANSPOSE('Sheet2'!$E2:$AB2))
重点是“Sheet2”范围内的行必须添加 1 行,例如:
=SUMPRODUCT('Sheet1'!C$2:C$25;TRANSPOSE('Sheet2'!$E3:$AB3))
但是每次我拖动或粘贴公式时系统都会添加 4 行:
=SUMPRODUCT('Sheet1'!C$2:C$25;TRANSPOSE('Sheet2'!$E6:$AB6))
=SUMPRODUCT('Sheet1'!C$2:C$25;TRANSPOSE('Sheet2'!$E10:$AB10))
请帮忙
这是添加到您的工作表中的一种方法,您可以测试一下:
=reduce(tocol(;1);B2:index(B:B;match(;0/(B:B<>"")));lambda(a;c;vstack(a;if(c="";tocol(;1);reduce(torow(;1);sequence(12);lambda(f;q;hstack(f;
let(w;sumproduct(choosecols('materials / work'!C2:N49;q);tocol(filter(production!C:AX;production!B:B=c)));x;if(w=0;;w);y;offset(c;;2);z;y-x;Σ;iferror(z/y);Λ;iferror(z/x);
vstack(x;z;Σ;Λ)))))))))
如果您仍然想使用公式拖动方法,跳过某些行,并保留公式中第二个范围的增量范围,您可能还想尝试使用自定义脚本,该脚本将使用
onEdit
事件以编程方式更新拖动的公式。请参阅此示例脚本:
/**
* Custom Google Sheets script triggered on an edit event.
* This sample script is designed to be used in Google Sheets & is activated on any edit event.
*
* It takes the currently selected range, retrieves the formulas, & then creates a modified version
* of the data by removing every xRows-th row. The modified data is then pasted back into the sheet, starting from the
* edited cell's row and column, with new, updated, and incremented ranges for the second range in the function (e.g., production!$C2:$AX2).
*
* @param {Object} e - The event object representing the edit event in Google Sheets.
*/
function onEdit(e) {
const draggedRange = e.source.getSelection().getActiveRange();
const draggedFormulas = draggedRange.getFormulas();
const xRows = 4;
const rowStart = e.range.rowStart;
const column = e.range.getColumn();
const finalData = draggedFormulas.map((row, i) =>
row.map(x =>
(i + 1) % xRows == 0 && i != 0 ? x : ''
)
);
e.source.getActiveSheet().getRange(rowStart, column, finalData.length).setValues(finalData);
}
注意:此方法将删除现有的单元格数据。创建工作表文件的新副本时使用它。