I have limited experience with JavaScript and I've been putting together the code I need by searching online resources and watching videos. My goal is to set multiple columns in row 4, starting from column 18 to the last column, as the active cells for copying and then pasting formulas down to the last row based on data in column 4. The current code selects all data from column 18 through the last column as intended, but it also extends the selection down to the last row unintentionally. Does anyone know how to correct this issue?
function CopyFormulasDown() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var sRA4 = ss.getRange(4,1); //First copy is A4 ..this one works as intended
var lr = ss.getLastRow();
var lc = ss.getLastColumn();
var sRR4lc = ss.getRange('R4:'+ lc +'4'); //Trying to select R4 through last col within row4; also tried (4,18+':'+lc), but throws an error: Exception: Cannot convert '18:37' to int.
var fillDownRangeA4 = ss.getRange(4,1,lr);
var fillDownRangeR4lc = ss.getRange(4,18,lr,lc);
// sRA4.activate(); //range cell A4 is copied
//sRA4.copyTo(fillDownRangeA4); //copied cell pastes formula down to last row ..WORKS!
sRR4lc.activate(); //ROW4 COL18 is selected through to last col as intended, but also selects down to last row.... problem is I didn't tell it to select past row 4... not sure how to correct this
// sRR4lc.copyTo(fillDownRangeR4lc); //commented out for now until I can get just row 4 from col 18 through last col copy to work
};