I have a 2 separate scripts that ask users for their start mileage (entered into column 3) and end mileage (entered into column 4). How can i get the total miles entered into column 10 after the end mileage is entered? I have tried entering a function on the sheet but that gets overwritten by the next data input.
My 2 script look like this:
var StartMileage = SpreadsheetApp.getUi().prompt("Please enter Start Mileage.").getResponseText(); var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Retrieval Log P1CU X") var NewLog = ss.getRange(ss.getLastRow(), 3).setValue( StartMileage );
and,
var Home = SpreadsheetApp.getUi().prompt("What is your end mileage?").getResponseText(); var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Retrieval Log P1CU X") var NewLog = ss.getRange(ss.getLastRow(), 4).setValue( Home );
The basic sum i want is the value of 'Home' minus the value of 'StartMileage' placed into column 10.
The script is set to run on the click of a button in which they will have to submit a response, the first button will ask their name and start mileage, the last button will ask their end mileage, the buttons will be clicked in order and both submissions will submit onto the same row. I want the script to do the calculations at the same time the end mileage is submitted, that function looks like this:
function promptHome() { var Home = SpreadsheetApp.getUi().prompt("What is your end mileage?").getResponseText(); var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Retrieval Log P1CU X") var NewLog = ss.getRange(ss.getLastRow(), 4).setValue( Home ); var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Retrieval Log P1CU X") var NewLog = ss.getRange(ss.getLastRow(), 9).setValue( new Date() ); }