Created
November 4, 2017 15:46
-
-
Save anonymous/3a55d69381b03d1335e62363fa09fb79 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function CaptureNetWorth() { | |
var USD_NW_COLUMN = 2; | |
var destinationSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Daily NW'); | |
// Get index of the last row in column A that doesn't have content | |
var Avals = destinationSheet.getRange("A1:A").getValues(); | |
var lastRowIndex = Avals.filter(String).length; | |
var newRowIndex = lastRowIndex + 1; | |
insertDate(destinationSheet, 1, newRowIndex); | |
getUSDCell().copyValuesToRange(destinationSheet, USD_NW_COLUMN, USD_NW_COLUMN, newRowIndex, newRowIndex); | |
} | |
function getUSDCell() { | |
var sourceSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Net Worth'); | |
var sourceTotalRef = "$A$1"; | |
var sourceCell = sourceSheet.getRange(sourceTotalRef); | |
return sourceCell; | |
} | |
function insertDate(sheet, x, y) { | |
// insert date | |
function pad(number) { | |
if (number < 10) { | |
return '0' + number; | |
} | |
return number; | |
} | |
function fmt(date) { | |
return date.getUTCFullYear() + | |
'-' + pad(date.getUTCMonth() + 1) + | |
'-' + pad(date.getUTCDate()); | |
}; | |
var d = new Date(); | |
sheet.getRange(y, x).setValue(fmt(d)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment