fix the error in the following
- User
fix the error in the following
- Assistant
I'm sorry, but I cannot fix an error without knowing what the error is. Please provide more information.
- User
function onEdit(e) {
addTimestamp(e);
} fix the error
function addTimestamp(e) { // https://www.youtube.com/watch?v=548dD3iXetg&t=265s&ab_channel=LearnGoogleSheets%26ExcelSpreadsheets var startRow = 2; var targetColumn = 1; var ws = "";
// get modified row and colum var row = e.range.getRow(); var col = e.range.getColumn();
if(col === tagetColumn && row >= startRow && e.source.getActiveSheet().getName() === ws){
var currentDate = new Date(); e.source.getActiveSheet().getRange(row,4).setValue(currentDate); if(e.source.getActiveSheet().getRange(row,3).getValue() == "اخراج العيون - الملح"){ e.source.getActiveSheet().getRange(row,3).setValue(currentDate); } // End If check if date created exists} //End IF check column, row, worksheet } //End function addTimestamp
- Assistant
There are no syntax errors in the provided code. However, there is a spelling mistake in the code. The variable
tagetColumnshould be corrected totargetColumn. - User
function onEdit(e) {
addTimestamp(e);
}
function addTimestamp(e) { // https://www.youtube.com/watch?v=548dD3iXetg&t=265s&ab_channel=LearnGoogleSheets%26ExcelSpreadsheets var startRow = 2; var targetColumn = 1; var ws = "";
// get modified row and colum var row = e.range.getRow(); var col = e.range.getColumn();
if(col === targetColumn && row >= startRow && e.source.getActiveSheet().getName() === ws){
var currentDate = new Date(); e.source.getActiveSheet().getRange(row,4).setValue(currentDate); if(e.source.getActiveSheet().getRange(row,3).getValue() == "اخراج العيون - الملح"){ e.source.getActiveSheet().getRange(row,3).setValue(currentDate); } // End If check if date created exists} //End IF check column, row, worksheet } //End function addTimestamp
- Assistant
The corrected code looks fine, please let me know if there is any other issue.
- Assistant
I'm sorry, but it seems like you did not provide any code or ask any question. Please provide more information on how I can assist you.
- User
fix the above
- Assistant
There is no code provided in your question. Could you please clarify what needs to be fixed?
- User
fix the code
- Assistant
I apologize, but there is no code provided in your question or previous message. Please provide the code that you want me to fix, along with a description of the issue you are facing.
- User
fix the code
function onEdit(e) {
addTimestamp(e);
}
function addTimestamp(e) { // https://www.youtube.com/watch?v=548dD3iXetg&t=265s&ab_channel=LearnGoogleSheets%26ExcelSpreadsheets var startRow = 2; var targetColumn = 1; var ws = "";
// get modified row and colum var row = e.range.getRow(); var col = e.range.getColumn();
if(col === targetColumn && row >= startRow && e.source.getActiveSheet().getName() === ws){
var currentDate = new Date(); e.source.getActiveSheet().getRange(row,4).setValue(currentDate); if(e.source.getActiveSheet().getRange(row,3).getValue() == "اخراج العيون - الملح"){ e.source.getActiveSheet().getRange(row,3).setValue(currentDate); } // End If check if date created exists} //End IF check column, row, worksheet } //End function addTimestamp
- Assistant
The code looks fine, but it lacks proper documentation that describes what the script does, what the inputs are, and what the expected output is. You could add comments to the code to document it better. Here's an example of how you could improve the comments:
/** * Adds a timestamp to the 4th column of a row when a cell in the 1st column of that row is edited. * If the cell in the 3rd column of that row contains the text "اخراج العيون - الملح", * then a timestamp is added to the cell in the 3rd column of that row as well. * * @param {Object} e The edit event object. */ function addTimestamp(e) { // The row number of the first row where the script should run. var startRow = 2; // The column number of the edited cell that should trigger the script. var targetColumn = 1; // The name of the sheet where the script should run. Leave empty if it should run on all sheets. var ws = ""; // Get the row and column number of the edited cell. var row = e.range.getRow(); var col = e.range.getColumn(); // Check if the edited cell is in the target column of a row where the script should run. if (col === targetColumn && row >= startRow && e.source.getActiveSheet().getName() === ws) { // Add the current date and time to the 4th column of the edited row. var currentDate = new Date(); e.source.getActiveSheet().getRange(row, 4).setValue(currentDate); // If the cell in the 3rd column of the edited row contains the text "اخراج العيون - الملح", // then add a timestamp to that cell as well. if (e.source.getActiveSheet().getRange(row, 3).getValue() == "اخراج العيون - الملح") { e.source.getActiveSheet().getRange(row, 3).setValue(currentDate); } } } - User
function onEdit(e) {
addTimestamp(e);
}
chabge the current code to write only in one cell function addTimestamp(e) { // https://www.youtube.com/watch?v=548dD3iXetg&t=265s&ab_channel=LearnGoogleSheets%26ExcelSpreadsheets var startRow = 2; var targetColumn = 1; var ws = "Eye";
// get modified row and colum var row = e.range.getRow(); var col = e.range.getColumn();
if(col === targetColumn && row >= startRow && e.source.getActiveSheet().getName() === ws){
var currentDate = new Date(); e.source.getActiveSheet().getRange(row,5).setValue(currentDate); if(e.source.getActiveSheet().getRange(row,3).getValue() == ""){ e.source.getActiveSheet().getRange(row,3).setValue(currentDate); } // End If check if date created exists} //End IF check column, row, worksheet } //End function addTimestamp
- Assistant
Here's the modified code to write the timestamp in a specific cell instead of the entire column:
function onEdit(e) { addTimestamp(e); } function addTimestamp(e) { var startRow = 2; var targetColumn = 1; var ws = "Eye"; var timestampCell = "E2"; var row = e.range.getRow(); var col = e.range.getColumn(); if (col === targetColumn && row >= startRow && e.source.getActiveSheet().getName() === ws) { var currentDate = new Date(); // Write the current date and time to the specified cell. e.source.getActiveSheet().getRange(timestampCell).setValue(currentDate); // If the cell in the 3rd column of the edited row is empty, // then write the current date and time to that cell as well. if (e.source.getActiveSheet().getRange(row, 3).getValue() === "") { e.source.getActiveSheet().getRange(row, 3).setValue(currentDate); } } }This code will write the timestamp in cell
E2. If you want to write the timestamp in a different cell, you can modify thetimestampCellvariable to the desired cell reference. - User
change the code to be in write the date only in cell e2 and any modified date to be in cell e3
function addTimestamp(e) { // https://www.youtube.com/watch?v=548dD3iXetg&t=265s&ab_channel=LearnGoogleSheets%26ExcelSpreadsheets var startRow = 2; var targetColumn = 1; var ws = "Eye";
// get modified row and colum var row = e.range.getRow(); var col = e.range.getColumn();
if(col === targetColumn && row >= startRow && e.source.getActiveSheet().getName() === ws){
var currentDate = new Date(); e.source.getActiveSheet().getRange(row,5).setValue(currentDate); if(e.source.getActiveSheet().getRange(row,3).getValue() == ""){ e.source.getActiveSheet().getRange(row,3).setValue(currentDate); } // End If check if date created exists} //End IF check column, row, worksheet } //End function addTimestamp
- Assistant
Here's the modified code that writes the date only in cell
E2and modified dates in cellE3:function onEdit(e) { addTimestamp(e); } function addTimestamp(e) { var startRow = 2; var targetColumn = 1; var ws = "Eye"; var timestampCell1 = "E2"; var timestampCell2 = "E3"; var row = e.range.getRow(); var col = e.range.getColumn(); if (col === targetColumn && row >= startRow && e.source.getActiveSheet().getName() === ws) { var currentDate = new Date(); // If the timestamp cell is empty, write the current date and time to that cell. // Otherwise, write the current date and time to the modified timestamp cell. var timestamp = e.source.getActiveSheet().getRange(timestampCell1).getValue(); if (timestamp === "") { e.source.getActiveSheet().getRange(timestampCell1).setValue(currentDate); } else { e.source.getActiveSheet().getRange(timestampCell2).setValue(currentDate); } } }This code first checks if cell
E2is empty. If it is empty, the current date and time are written toE2. If it is not empty, the current date and time are written toE3. This way, the first timestamp will always be inE2, and any subsequent timestamps will be in . - User
fix the code function addTimestamp(e) { var startRow = 2; var targetColumn = 1; var ws = “Eye”; var timestampCell1 = “E2”; var timestampCell2 = “E3”;
var row = e.range.getRow(); var col = e.range.getColumn();
if (col === targetColumn && row >= startRow && e.source.getActiveSheet().getName() === ws) { var currentDate = new Date();
// If the timestamp cell is empty, write the current date and time to that cell. // Otherwise, write the current date and time to the modified timestamp cell. var timestamp = e.source.getActiveSheet().getRange(timestampCell1).getValue(); if (timestamp === “”) { e.source.getActiveSheet().getRange(timestampCell1).setValue(currentDate); } else { e.source.getActiveSheet().getRange(timestampCell2).setValue(currentDate); } } }
- Assistant
I apologize, there was no error in the previous code that needed to be fixed. However, I noticed that the quotation marks around "Eye", "E2", and "E3" may cause issues. Please replace these quotation marks with normal double quotes, like so:
function addTimestamp(e) { var startRow = 2; var targetColumn = 1; var ws = "Eye"; var timestampCell1 = "E2"; var timestampCell2 = "E3"; var row = e.range.getRow(); var col = e.range.getColumn(); if (col === targetColumn && row >= startRow && e.source.getActiveSheet().getName() === ws) { var currentDate = new Date(); // If the timestamp cell is empty, write the current date and time to that cell. // Otherwise, write the current date and time to the modified timestamp cell. var timestamp = e.source.getActiveSheet().getRange(timestampCell1).getValue(); if (timestamp === "") { e.source.getActiveSheet().getRange(timestampCell1).setValue(currentDate); } else { e.source.getActiveSheet().getRange(timestampCell2).setValue(currentDate); } } }Using the normal double quotes will avoid syntax errors when running the code.
- User
still the output not present
- Assistant
If the code is not producing the output you expect, there could be a few issues to check:
- Make sure you have set up the trigger for the
onEditfunction. Go to the "Edit" menu in your Google Sheets document, select "Current project's triggers", and make sure there is a trigger set up for theonEditfunction. - Check that the sheet name and cell references in your code are correct. Make sure that the sheet name and cell references match the name and location of the cell(s) you want to modify. If you have changed the name or location of the cell(s), then you will need to update the code accordingly.
- Try running the code manually. You can do this by going to the "Tools" menu in your Google Sheets document and selecting "Script editor". In the script editor, select the
addTimestampfunction and click the "Run" button. This will run the function with a default edit event and help you identify any issues with the code. - Check that you have the necessary permissions to run the script. Make sure that you are logged in to the correct Google account and that you have permission to modify the document.
- Make sure you have set up the trigger for the