When creating Google Sheets scripts, you may encounter scenarios where you need multiple onEdit functions to handle different edit events. However, a single script cannot have two functions with the same name. To resolve this conflict, consider the following approach:
function onEdit(e) { onEdit1(e); onEdit2(e); }
In this merged function,
This approach ensures that both functions are executed whenever an edit is made in the spreadsheet. However, you can still use conditional statements to execute specific actions based on the conditions set in the respective functions.
Consider the following example where one function manages dependent dropdown lists (onEdit1) and the other adds rows based on checkbox selections (onEdit2):
function onEdit(e) { if (e.range.columnStart === 4 && e.range.getValue() === true) { onEdit2(e); } else { onEdit1(e); } } function onEdit1(e) { // Dependent Dropdown List functionality } function onEdit2(e) { // Add row by checkbox functionality }
In this script, the merged onEdit function checks if the edit occurs in column 4 with a true value (checkbox selected). If so, it calls the onEdit2 function. Otherwise, it calls the onEdit1 function.
For further reference, you can consult the following resources:
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3