-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCrypto_ticker
31 lines (25 loc) · 1.3 KB
/
Crypto_ticker
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function recordDailyValue() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sourceSheet = spreadsheet.getSheetByName('Sheet1'); // Replace 'Sheet1' with the name of your source sheet
var targetSheet = spreadsheet.getSheetByName('Sheet2'); // Replace 'Sheet2' with the name of your target sheet
var targetColumn = 2; // Replace '2' with the desired target column number (e.g., 1 for column A, 2 for column B, and so on)
var currentValue = sourceSheet.getRange('A1').getValue(); // Replace 'A1' with the cell reference you want to record
var targetRow = getNextAvailableRow(targetSheet, targetColumn);
var targetRange = targetSheet.getRange(targetRow, targetColumn);
var dateCell = targetSheet.getRange(targetRow, targetColumn - 1); // Corresponding cell to the left of the target cell
targetRange.setValue(currentValue);
dateCell.setValue(new Date()); // Set the current date
}
function getNextAvailableRow(sheet, column) {
var columnValues = sheet.getRange(1, column, sheet.getMaxRows()).getValues();
var lastRowIndex = columnValues.reverse().findIndex(function(row) {
return row[0] !== '';
});
var nextAvailableRow;
if (lastRowIndex === -1) {
nextAvailableRow = 1;
} else {
nextAvailableRow = sheet.getMaxRows() - lastRowIndex + 1;
}
return nextAvailableRow;
}