![](/img/trans.png)
[英]Google Script to copy specific columns from one sheet to another sheets last row onEdit
[英]Google Sheets OnEdit script: copy value from specific columns
我們正在使用Google工作表來跟蹤出勤情況。 以前,每個階段的教師都輸入P,T或A(目前,遲到,缺席)。 我仍然希望用戶可以選擇在一周中的每個期間輸入一個值,但是如果他們可以一整天都輸入一個值,那將節省大量時間。
我想要的是,如果將一個值輸入到帶有“ P”或“ A”的“ 0”時段(綠色列)中的任何一個(數據驗證限制了這些選項),則OnEdit函數會復制相同的字母( “ P”或“ A”)到以下8列,然后刪除原始值 。 (不刪除,最右邊列的總數將關閉)。 我不希望基於任何非綠色列中的編輯來激活OnEdit 。
我最終將有幾個選項卡,每個選項卡在不同的星期,但每個選項卡都完全相同...因此,我認為該功能應該在活動表中使用。
https://docs.google.com/spreadsheets/d/1NKIdNY4k66r0zhJeFv8jYYoIwuTq0tCWlWin5GO_YtM/edit?usp=sharing
謝謝您的幫助,
我寫了一些代碼來幫助您開始您的項目。 (我也是一名老師)您將必須根據自己的需求進行一些更改,並且可能會對其進行優化以使其運行更快。 祝好運!
function onEdit(e) {
//create an array of the columns that will be affected
var allColumns = [2, 10];
//get the number values of the column and row
var col = e.range.getColumn();
var row = e.range.getRow();
//get the A1 notation of the editted cell for clearing it out
var cell = e.range.getA1Notation();
//only run if the cell is in a column in the allColumns array
if(allColumns.indexOf(col) > -1) {
//run the for loop for the next 8 cells
for(var i = col + 1; i < col + 9; i++) {
SpreadsheetApp.getActiveSheet().getRange(row, i).setValue(e.value);
SpreadsheetApp.getActiveSheet().getRange(cell).setValue('');
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.