英文:
How to add a row when a column is updated/changed?
问题
I have translated the code part for you:
function addRowOnEdit(e) {
var sheet = e.source.getActiveSheet();
var range = e.range;
// Define the trigger range
var triggerRange = sheet.getRange('M2:M');
// Check if the edited cell is within the trigger range
if (range.getColumn() === triggerRange.getColumn() && range.getRow() >= triggerRange.getRow() && range.getRow() <= triggerRange.getLastRow()) {
// Get the last row of the sheet
var lastRow = sheet.getLastRow();
// Insert a new row at the last row
sheet.insertRowAfter(lastRow);
// You can also add data to the newly added row if needed
var newRow = sheet.getRange(lastRow + 1, 1); // Adjust the column number if needed
newRow.setValue("New Data"); // Change "New Data" to the desired value
}
}
If you have any more text to translate or any questions, please let me know.
英文:
I have 2 sheets (Form Responses 1 & Sheet 2), the first one is receiving data from a google forms while the second references the first to do some calculations.
I'm using
=SUMIFS('Form responses 1'!C2:C;M2:M;month(A9))
to sum all the values in a given month in Sheet 2.
The M column is an array formula that updates the column with the months of every entry from Form Responses 1
Whenever a new entry is sent through the form, Form Responses 1 adds a new row to the sheet. SUMIFS does not work if both sheets are not the same size.
I need to make so that whenever the M column is updated in Sheet 2, it automatically adds 1 row so that it keeps the same size as Form Responses 1 as it gets new data added
I tried using a google script that has a trigger onChange
function addRowOnEdit(e) {
var sheet = e.source.getActiveSheet();
var range = e.range;
// Define the trigger range
var triggerRange = sheet.getRange('M2:M');
// Check if the edited cell is within the trigger range
if (range.getColumn() === triggerRange.getColumn() && range.getRow() >= triggerRange.getRow() && range.getRow() <= triggerRange.getLastRow()) {
// Get the last row of the sheet
var lastRow = sheet.getLastRow();
// Insert a new row at the last row
sheet.insertRowAfter(lastRow);
// You can also add data to the newly added row if needed
var newRow = sheet.getRange(lastRow + 1, 1); // Adjust the column number if needed
newRow.setValue("New Data"); // Change "New Data" to the desired value
}
}
答案1
得分: 0
尝试在SUMIF中使用该数组公式了吗?不仅要有列M,还要将它与SUMIF一起使用,但不使用它进行SUMIF。
=SUMIFS('Form responses 1'!C2:C;ARRAYFORMULA(MONTH('Form responses 1'!A2:A));month(A9))
英文:
Have you tried using that array formula inside the SUMIF? Instead of having column M, or along with having it but without using it for your SUMIF
=SUMIFS('Form responses 1'!C2:C;ARRAYFORMULA(MONTH('Form responses 1'!A2:A));month(A9))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论