function myFunction() {
var source = SpreadsheetApp.getActive().getSheetByName('Mechanic Sheet #1');
var target = SpreadsheetApp.getActive().getSheetByName('Fox');
target.activate();
var i = 19;
var range = target.getRange("B19:B500");
var data = range.getValues();
for (var i =19; i < data.length; i ){
if(!data[i][0]){
var sourceWorkDone = source.getRange("L10:S10").getValues();
var sourceLicensePlate = source.getRange("L13:S13").getValues();
var sourceCompanyProfit = source.getRange("I10").getValues();
var sourceMechanicFee = source.getRange("I9").getValues();
var targetWorkDone = target.getRange("B" i );
var targetLicensePlate = target.getRange("C" i);
var targetCompanyProfit = target.getRange("D" i);
var targetMechanicFee = target.getRange("E" i);
targetWorkDone.setValue(sourceWorkDone);
targetLicensePlate.setValue(sourceLicensePlate);
targetCompanyProfit.setValue(sourceCompanyProfit);
targetMechanicFee.setValue(sourceMechanicFee);
break;
}
}
}
我有“Mechanic's Sheet #1”,另一張叫做“Fox”,一張是價格和工單,第二張是記錄作業和員工工資的收據。
我需要將 Mechanic's Sheet #1 的 L10:S10 的值發送到 Fox B19 我需要將 Mechanic's Sheet #1 的 L13:S13 的值發送到 Fox C19 我需要將 Mechanic's Sheet #1 的 I10 的值發送到Fox D19 我需要將 Mechanic's Sheet #1 的 I9 的值發送到 Fox E19
但是我需要檢查 B19 是否為空,如果它不為空并且包含已提交的訂單,我需要將所有資料發送到下一個迭代,即 B20、C20、D20、E20。
但我仍然需要它檢查我需要它來檢查 B19 是否為空,直到它找到一個空白點來插入機械表 #1 中的資訊。
It is populating the new sheet with the correct info in slot B19 but it isn't populating B20 with anything and so on. if i change i it will populate the proper spot in the sheet. I can't tell if its the loop or what. First time using this language and would like to see where my mistake is.
Images of First Sheet https://i.imgur.com/XAjujAl.png
Images of Second sheet where i need info to loop. https://i.imgur.com/TP8fWE8.png
Copy of Document.
https://docs.google.com/spreadsheets/d/1Zol7OFwNvkncQfaDSCACFfHZ0ndyb7lBGwtDzjGT2zE/edit?usp=sharing
uj5u.com熱心網友回復:
根據您的問題陳述
試試這個示例腳本: -
function pasteValues() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const ssSource = ss.getSheetByName('Mechanic Sheet #1')
const ssTarget = ss.getSheetByName('Fox')
const sourceWorkDone = ssSource.getRange("L10").getValue();
const sourceLicensePlate = ssSource.getRange("L13").getValue();
const sourceCompanyProfit = ssSource.getRange("I10").getValue();
const sourceMechanicFee = ssSource.getRange("I9").getValue();
const checkEmptyRow = ssTarget.getRange('B18:B').getValues().flat().filter(r=> r).length
const emptyRowRange = ssTarget.getRange(`B${checkEmptyRow 18}`) // get Empty Row adding 18 as your header starts from it
emptyRowRange.setValue(sourceWorkDone)
emptyRowRange.offset(0, 1).setValue(sourceLicensePlate)
emptyRowRange.offset(0, 2).setValue(sourceCompanyProfit)
emptyRowRange.offset(0, 3).setValue(sourceMechanicFee)
}
如果細胞是,你不必使用
L10:S10等等merge此外,您不必遍歷資料,只需獲取范圍并過濾非空范圍并獲取長度
參考
抵消
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/441990.html
