I am trying to populate a form template on a sheet. Say the a1 locations of the fields on the form to populate are:
[B7, B9, D8, D11]
(In actuality, I have 65 different fields.)
I want to populate the fields with the corresponding set of values:
["Apple", "Banana", "Grape", "Orange"].
(In actuality, the values are coming from a database and will change.)
I have tried a 'for' loop but since I have 65 fields, it is very slow. I saw another post with the same goal, located here, which sets the target form sheet as an array and sets each field one by one to the targeted value. But since I have 65 fields, this would be super cumbersome to write out and very inefficient when I change fields around, etc.
It seems like getRangeList should have a counterpart with some version of setValues to accomplish this, or something like it, but I can't find anything.
There must be a better way! Please help!
Here is the 'for' loop I tried, simplified to the shortened list above. My data base has the cell addresses listed above the data, like this:
My code is as follows:
var app = SpreadsheetApp;
var activeSheet = app.getActiveSpreadsheet(); //Get current active spreadsheet
var dataSheet = activeSheet.getSheetByName('DataSheet');
var formSheet = activeSheet.getSheetByName('FormSheet');
function Load_Form(){
formSheet.activate();
for(i = 2; i<6; i++){
var dataLOC = dataSheet.getRange(1,i).getValue(); //gets a1 notation of form fields
var dataRANGE = formSheet.getRange(dataLOC); //activates the cells identified above
var dataVAL = dataSheet.getRange(2,i).getValue(); // gets values to place in form fields
dataRANGE.setValue(dataVAL);
}
}
Keep in mind that I actually have 65 fields, which is why the 'for' loop is so slow.