Comments on: A Simple Timestamp Google Sheets Tutorial for 2024 https://spreadsheetpoint.com/insert-timestamps-in-google-sheets/ Google Sheets Tips & Tutorials Thu, 15 Aug 2024 18:12:54 +0000 hourly 1 https://wordpress.org/?v=6.7.1 By: jmarkus https://spreadsheetpoint.com/insert-timestamps-in-google-sheets/#comment-14689 Mon, 06 May 2024 16:23:58 +0000 https://spreadsheetpoint.com/?p=802#comment-14689 In reply to Marko.

Good question here. How about something like this? I have the script below functioning so whenever a new row is added to Sheet2, the timestamp is automatically inserted into column A of that row.


function onEdit(e) {
var range = e.range;
var sheet = range.getSheet();

// Check if the edited range is in Sheet2 and the timestamp column
if (sheet.getName() == "Sheet2" && range.getColumn() == 2) { // Assuming the timestamp column is column B
var row = range.getRow();
var timestampCell = sheet.getRange(row, 1); // Assuming the timestamp should be in column A
if (!timestampCell.getValue()) { // Check if timestamp is not already set
timestampCell.setValue(new Date());
}
}
}

]]>
By: jmarkus https://spreadsheetpoint.com/insert-timestamps-in-google-sheets/#comment-14688 Mon, 06 May 2024 16:22:03 +0000 https://spreadsheetpoint.com/?p=802#comment-14688 In reply to John Milly.

Sure! Use an “onformsubmit” instead of “onedit”.


function onFormSubmit(e) {
var sheet = e.range.getSheet(); // Get the sheet where the form data is submitted
var user = Session.getActiveUser().getEmail(); // Get the email of the user who submitted the form
var timestamp = new Date(); // Get the current timestamp
var row = e.range.getRow(); // Get the row where the form data is submitted

// Assuming the timestamp column is column B, adjust the range accordingly
var timestampCell = sheet.getRange(row, 2); // Get the cell in the same row, but column B for timestamp
var userCell = sheet.getRange(row, 3); // Get the cell in the same row, but column C for user email

// Set the timestamp and user email in the corresponding cells
timestampCell.setValue(timestamp); // Set the timestamp in column B
userCell.setValue(user); // Set the user email in column C
}

]]>
By: jmarkus https://spreadsheetpoint.com/insert-timestamps-in-google-sheets/#comment-14685 Mon, 06 May 2024 16:17:18 +0000 https://spreadsheetpoint.com/?p=802#comment-14685 In reply to Sergey.

Just add in an “onedit” into the scrip. Here’s how it might look:

function onEdit(e) {
var range = e.range; // Get the edited range
var sheet = range.getSheet(); // Get the edited sheet
var user = Session.getActiveUser().getEmail(); // Get the email of the user who made the change
var timestamp = new Date(); // Get the current timestamp

// Check if the edited range is in a specific sheet and range
if (sheet.getName() == "Sheet1" && range.getColumn() == 1 && range.getRow() >= 2) {
var timestampCell = sheet.getRange(range.getRow(), 2); // Get the cell in the same row, but column B for timestamp
var userCell = sheet.getRange(range.getRow(), 3); // Get the cell in the same row, but column C for user email
timestampCell.setValue(timestamp); // Set the timestamp in column B
userCell.setValue(user); // Set the user email in column C
}
}

]]>
By: jmarkus https://spreadsheetpoint.com/insert-timestamps-in-google-sheets/#comment-13492 Fri, 02 Feb 2024 13:07:45 +0000 https://spreadsheetpoint.com/?p=802#comment-13492 In reply to Corey.

No problem! That’s a rare use case, but there’s a workaround. To add time stamps offline, use the onEdit trigger to automatically add a timestamp when a cell is modified. This trigger will work even when offline, but the changes will be applied once the spreadsheet regains an internet connection.

Here’s a simplified example of a script:
function onEdit(e) {
var sheet = e.source.getSheetByName('YourSheetName');
var range = e.range;
var timestampColumn = 2; // Adjust the column index where you want the timestamp

if (range.getColumn() !== timestampColumn) {
sheet.getRange(range.getRow(), timestampColumn).setValue(new Date());
}
}

]]>
By: jmarkus https://spreadsheetpoint.com/insert-timestamps-in-google-sheets/#comment-13482 Fri, 02 Feb 2024 12:57:50 +0000 https://spreadsheetpoint.com/?p=802#comment-13482 In reply to john.

Try something like:
=IFERROR(INDEX($A$2:$A$100, SMALL(IF($C$2:$C$100<>0, ROW($C$2:$C$100)-ROW($C$2)+1), ROW(1:1))), "")

]]>
By: jmarkus https://spreadsheetpoint.com/insert-timestamps-in-google-sheets/#comment-13475 Fri, 02 Feb 2024 12:50:27 +0000 https://spreadsheetpoint.com/?p=802#comment-13475 In reply to FATİH.

You can do this with an App Script:

function onEdit(e) {
var sheet = e.source.getSheetByName('YourSheetName'); // Replace 'YourSheetName' with your actual sheet name
var range = e.range;

// Check if the edited range is in the desired column (e.g., column B)
if (range.getColumn() == 2) {
// Get the username from the edited row in column A
var username = sheet.getRange(range.getRow(), 1).getValue();

// Stamp the current date in the column next to the username
sheet.getRange(range.getRow(), 3).setValue(new Date());
}
}

]]>
By: jmarkus https://spreadsheetpoint.com/insert-timestamps-in-google-sheets/#comment-13470 Fri, 02 Feb 2024 12:42:38 +0000 https://spreadsheetpoint.com/?p=802#comment-13470 In reply to Amy Frisch.

You can dynamically generate a timestamp and include it in the title of your PDF document.

Try this:
function convertSheetToPDFAndEmail() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getSheetByName('YourSheetName'); // Replace 'YourSheetName' with the actual sheet name
var range = sheet.getDataRange();
var data = range.getValues();
var urlColumnIndex = 1; // Adjust this to the column index where image URLs are located

// Create a timestamp for the title
var timestamp = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), 'yyyyMMdd_HHmmss');

// Fetch all image URLs
var imageUrls = [];
for (var i = 1; i < data.length; i++) { var imageUrl = data[i][urlColumnIndex - 1]; // Adjust to 0-based index imageUrls.push(imageUrl); } // Create a temporary folder var folder = DriveApp.createFolder('TempFolder'); // Fetch and resize images var images = []; for (var i = 0; i < imageUrls.length; i++) { var imageUrl = imageUrls[i]; var imageBlob = UrlFetchApp.fetch(imageUrl).getBlob(); var resizedBlob = resizeImage(imageBlob, 200, 200); // Adjust the width and height as needed var imageFile = folder.createFile(resizedBlob); images.push(imageFile.getBlob()); } // Create a temporary sheet for PDF conversion var tempSheet = spreadsheet.insertSheet('TempSheet_' + timestamp); // Include timestamp in the sheet name tempSheet.getRange(1, 1, data.length, data[0].length).setValues(data); // Insert resized images into the temporary sheet for (var i = 0; i < images.length; i++) { tempSheet.insertImage(images[i], 1, data.length + i + 1); // Adjust column index } // Convert the temporary sheet to PDF var pdf = folder.createFile(tempSheet.getAs('application/pdf').getBytes()); // Email the PDF to the user MailApp.sendEmail({ to: 'user@example.com', // Replace with the recipient's email address subject: 'PDF_with_Images_' + timestamp, // Include timestamp in the subject body: 'Please find the attached PDF with images generated on ' + timestamp + '.', attachments: [pdf] }); // Clean up: Delete the temporary folder and sheet folder.setTrashed(true); spreadsheet.deleteSheet(tempSheet); } function resizeImage(blob, width, height) { var base64 = Utilities.base64Encode(blob.getBytes()); var resizedBase64 = Utilities.base64EncodeWebSafe(Utilities.newBlob(Utilities.base64DecodeWebSafe(base64)).getResize(width, height).getBytes()); return Utilities.newBlob(Utilities.base64DecodeWebSafe(resizedBase64)); }

]]>
By: Juneil https://spreadsheetpoint.com/insert-timestamps-in-google-sheets/#comment-12118 Sat, 09 Sep 2023 09:32:25 +0000 https://spreadsheetpoint.com/?p=802#comment-12118 is there any way that next cell will only be updated if the Column is edited by a specific string?

function onEdit() {

var s = SpreadsheetApp.getActiveSheet();

if( s.getName() == “Sheet1″ ) { //checks that we’re on Sheet1 or not

var r = s.getActiveCell();

if( r.getColumn() == 1 ) { //checks that the cell being edited is in column A

var nextCell = r.offset(0, 1);

if( nextCell.getValue() === ” ) //checks if the adjacent cell is empty or not?

nextCell.setValue(new Date());

}

}

}

]]>
By: chris k antoni https://spreadsheetpoint.com/insert-timestamps-in-google-sheets/#comment-11964 Mon, 14 Aug 2023 05:55:36 +0000 https://spreadsheetpoint.com/?p=802#comment-11964 thank you so much.. works amazingly at 1st try

]]>
By: John Hampton https://spreadsheetpoint.com/insert-timestamps-in-google-sheets/#comment-11929 Fri, 11 Aug 2023 20:44:37 +0000 https://spreadsheetpoint.com/?p=802#comment-11929 I am creating a laboratory log and I want to reverse the function so that every time I add data to any column other than A, Column A populated the date on that row? Can someone help me, I have no clue what I am doing?

]]>