I'm running a script which automatically generates values for the A and B columns, and then I want to copy the values generated through the E-I columns (columns C and D run formulas to print out values of E-I), and copy them into J-N (the initial values reload every time I open the sheet, so I'd like to just copy their value instead of using =E2 for example). This is what I'm working with so far:
function daily() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh = ss.getSheetByName("Instagram");
var date = Utilities.formatDate(new Date(), "GMT", "YYYY-MM-DD");
var aValues = sh.getRange("A1:A").getValues();
var aLast = aValues.filter(String).length;
// Assuming A and B have same last row, no need for B
// If different, need to calculate separately
var bValues = sh.getRange("B1:B").getValues();
var bLast = bValues.filter(String).length;
// If A and B are the same, use setValues
sh.getRange(aLast + 1, 1, 1, 2).setValues([[date,'microdosehq']]);
var sheet = SpreadsheetApp.getActiveSheet();
var balance = sheet.getRange("E1:E").getValues();
var nextRow = getFirstEmptyRow('J');
// Record current balance and timestamp at end of columns B & C
sheet.getRange(nextRow, 10, 1, 1).setValues([[balance]]);
}
// From https://stackoverflow.com/a/9102463/1677912
function getFirstEmptyRow(columnLetter) {
columnLetter = columnLetter || 'A';
var rangeA1 = columnLetter + ':' + columnLetter;
var spr = SpreadsheetApp.getActiveSpreadsheet();
var column = spr.getRange(rangeA1);
var values = column.getValues(); // get all data in one call
var ct = 0;
while ( values[ct][0] != "" ) {
ct++;
}
return (ct+1); // +1 for compatibility with spreadsheet functions
}
But it's always returning the value of E1 into the next available J cell, and right now I'm not focused on all the columns, just column E. I've added an image here to show what I'd like to accomplish at the end of the day.
Any extra support would be much appreciated!