
我有一張如上圖所示的表格。C386:D392每當 D 列中有編輯時,我都希望根據 D 列對范圍進行排序。
C386來自桌子的頂部。
D392來自 386 到 C 列中的填充行數。我已經在 B385 中計算了 C 列。
我不知道為什么不起作用。變數“cox”和“y”是我創建要排序范圍的兩個變數
function onEdit(e) {
var sheet = SpreadsheetApp.getActiveSheet();
var spreadsheet = SpreadsheetApp.getActive()
var d = SpreadsheetApp.getActiveSheet().getRange('D:D').getColumn();
var row = e.range.getRow();
var col = e.range.getColumn();
if(col == d){
var valor = sheet.getRange(row,1).getValue();
var x = sheet.getRange(row-valor,3).getRow();
var cant = sheet.getRange(row-valor-1,2).getValue();
var y = sheet.getRange(x cant,4).getCell();
var cox = sheet.getRange(x,col-1).getCell();
spreadsheet.getRange(`${cox}:${y}`).activate()
.sort({column: 4, ascending: true});
}
}
uj5u.com熱心網友回復:
模板文字
在評論中很難做到。但是范圍內的內部運算式必須像這樣被反勾號包圍。
spreadsheet.getRange(`${cox}:${y}`).activate() .sort({column: 4, ascending: true});
我相信這些被稱為模板文字,您可以在此處了解有關它們的更多資訊
uj5u.com熱心網友回復:
- 使用模板文字
- 硬編碼
C和D,如果你只使用C:D - 根據使用情況,
getDataRegion()也可能對您的情況有所幫助。
/**
* @param {GoogleAppsScript.Events.SheetsOnEdit} e
*/
function onEdit(e) {
const sheet = e.range.getSheet();
const row = e.range.getRow();
const col = e.range.getColumn();
if (col === 4) {
const indexFromA = sheet.getRange(row, 1).getValue();
const topRow = row - indexFromA;
const countFromB = sheet.getRange(topRow - 1, 2).getValue();
const bottomRow = topRow countFromB;
sheet.getRange(`C${topRow}:D${bottomRow}`).sort(4);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/379141.html
