Irgendwelche schnellen Lösungen, die dafür sorgen könnten, dass sie in einem Skript zusammenarbeiten?
Code: Select all
function onEdit(e) {
const sheetName = 'CUSTOM CUTS'; // Replace with your actual sheet name
const dropdownColumn = 5; // Column number for the dropdown (e.g., Column C is 3)
const dateColumn = 6; // Column number for the date (e.g., Column D is 4)
const range = e.range;
const sheet = range.getSheet();
// Check if the edited sheet is the correct one
if (sheet.getName() !== sheetName) {
return;
}
// Check if the edited column is the dropdown column
if (range.getColumn() === dropdownColumn) {
const row = range.getRow();
const cellValue = range.getValue();
const dateCell = sheet.getRange(row, dateColumn);
// If a value is selected in the dropdown, add a timestamp
if (cellValue) {
// Check if the date cell is empty to avoid overwriting existing dates
if (!dateCell.getValue()) {
dateCell.setValue(new Date());
// Optional: Format the date cell to a desired format within the script
dateCell.setNumberFormat("MM/dd/yyyy");
}
} else {
// Optional: Clear the date cell if the dropdown selection is cleared
dateCell.clearContent();
}
}
}
function onEdit(e) {
const sheetName = 'CUSTOM CUTS'; // Replace with your actual sheet name
const columnToDelete = 5; // Replace with the column number of your dropdown (e.g., D is 4)
const valueToDelete = 'COMPLETE' || 'CANCEL'; // Replace with the specific dropdown value that triggers deletion
const range = e.range;
const sheet = range.getSheet();
if (sheet.getName() === sheetName && range.getColumn() === columnToDelete && range.getValue() === valueToDelete) {
sheet.deleteRow(range.getRow());
}
}
function onEdit(event){
var sheet = event.source.getActiveSheet();
// Replace 'Sheet1' with the name of your sheet
if (sheet.getName() == 'CUSTOM CUTS') {
var editedCell = sheet.getActiveCell();
var columnToSortBy = 1; // Replace '1' with your date column number
var tableRange = "A8:F"; // Replace 'A2:D' with your data range, excluding headers
// Optional: only sort if a specific column is edited
// if(editedCell.getColumn() == columnToSortBy){
var range = sheet.getRange(tableRange);
// '1' is the column index for sorting; 'false' is for descending order (newest first)
range.sort({column: columnToSortBy, ascending: false});
// }
}
}
Mobile version