Try this:
function test2() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var today = ss.getSheetByName("Today");
var program = ss.getSheetByName("Program");
var date = today.getRange("B4").getValue();
var targetDates = program.getRange("D4:KL4").getValues();
var column;
// Get the target column.
for (var i = 0; i < targetDates[0].length; i++){
if (targetDates[0][i].toString() == date.toString()){
column = i + 4; // To account for the first cols.
Logger.log("found the date " + targetDates[0][i] + " at column " + column + " with i = " + i);
break;
}
else continue;
}
// Move the values.
today.getRange("B11:G11").moveTo(program.getRange(11, column)); // Sq w/ Belt
today.getRange("J11:O11").moveTo(program.getRange(16, column)); // 2ct Paused Squat
today.getRange("R11:W11").moveTo(program.getRange(21, column)); // Pin Squat
today.getRange("Z11:AE11").moveTo(program.getRange(26, column)); // 3-0-3 Tempo Squat
today.getRange("AH11:AM11").moveTo(program.getRange(31, column)); // Sq no Belt
today.getRange("B19:H19").moveTo(program.getRange(37, column)); // 1 Ct Paused Bench Press
today.getRange("J19:O19").moveTo(program.getRange(42, column)); // Overhead Press w/ Belt
today.getRange("R19:W19").moveTo(program.getRange(47, column)); // Close Grip Bench Press
today.getRange("Z19:AE19").moveTo(program.getRange(52, column)); // 2 Ct Paused Bench Press
today.getRange("AH19:AM19").moveTo(program.getRange(57, column)); // 3 Ct Paused Bench Press
today.getRange("AP19:AU19").moveTo(program.getRange(62, column)); // Pin Bench Press
today.getRange("B27:H27").moveTo(program.getRange(68, column)); // Deadlift w/ Belt
today.getRange("J27:O27").moveTo(program.getRange(73, column)); // Rack Pull - mid shin
today.getRange("R27:W27").moveTo(program.getRange(78, column)); // 2 ct Paused Deadlift
today.getRange("AH27:AM27").moveTo(program.getRange(83, column)); // Pendlay Rows
}
A couple things, I used moveTo()
(documentation here), which cuts/pastes the values to the target, the only issue is that it overwrites the style format. When working with Sheets it's always better to use getValues()
and setValues()
to avoid making multiple calls to the API. In this case, however, since your data was organized in such a particular way it was better to work like this for complexity's sake. Please let me know if you have any doubts. I tested it on a copy of the sheet you provided and it worked as intended.