1

I am trying to create a code to Google Spreadsheets . In VBA code it is very simple. My goal is, when a particular cell is filled , another cell displays the date and time of completion .

In VBA:

Function DateTime()
  DateTime = NOW
End Function
3

2 Answers 2

1

Based on your most recent comment stating that you want to call a custom function from the Google Sheet frontend, all you will need in your Script Editor (backend) is:

function timeStamp() {
  return new Date();
}

You can then call that function from a formula in your Sheet, very similar to what you wrote already:

=IF( ISBLANK(A1), "", timeStamp() )
0
0

This is the code that will help you out of what you are trying to achieve.

Code below will add the date in the very next column of whichever field you will input a value into.

//onEdit is the default "on edit event handler" provided by google app script
function onEdit(e){
  var spreadSheet = e.source;
  var sheet = spreadSheet.getActiveSheet();
  var range = e.range;
  //only add the date in the next column if value in cell is not empty
  if(range.getValue() != ""){
    var col = range.getColumn();
    var row = range.getRow();
    //get the very next column
    var newRange = sheet.getRange(row, col + 1);
    newRange.setValue(new Date());
  }
}

Hope this will help.

NB: Please note this code will work with scripts bound to google apps only.

2
  • Hello , apparently did not work. I believe that my need is more simple. I need to put together a formula IF(IFSBLANK(A1);" ";myFunction ( ) ) . In other words , I need myFunction given the fixed date and time so that A1 is met . Its formula has not done this and not become scalable - the tests I did. Example: docs.google.com/spreadsheets/d/… Jul 28, 2016 at 16:49
  • 1
    @GabrielPiffer: Relevante information regarding the question should be included on the question.
    – Rubén
    Oct 31, 2016 at 22:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.