Reputation: 295
I was wondering if there was any way I could shorten the script below? As you can see, I copied the eight lines (B13-I13) to make a new one with a different row (B4-I14). However, I must continue it until row 23.
var values = [[formS.getRange("C7").getValue(),
formS.getRange("C8").getValue(),
formS.getRange("D9").getValue(),
formS.getRange("B13").getValue(), <--- shorten this
formS.getRange("C13").getValue(),
formS.getRange("D13").getValue(),
formS.getRange("E13").getValue(),
formS.getRange("F13").getValue(),
formS.getRange("G13").getValue(),
formS.getRange("H13").getValue(),
formS.getRange("I13").getValue(), ----> to this
formS.getRange("B14").getValue(), <--- shorten this
formS.getRange("C14").getValue(),
formS.getRange("D14").getValue(),
formS.getRange("E14").getValue(),
formS.getRange("F14").getValue(),
formS.getRange("G14").getValue(),
formS.getRange("H14").getValue(),
formS.getRange("I14").getValue(), ----> to this
]];
This is the script that I'm using..
function SaveData() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var formS = ss.getSheetByName("Form");
var dataS = ss.getSheetByName("Data");
--> LOCATION OF THE SCRIPT ABOVE <---
dataS.getRange(dataS.getLastRow()+1,1,1,11).setValues(values);
ClearCell();
}
Please see the sample picture below where I encode the data.
This is the sample image of the sheet where the data were being saved.
Upvotes: 1
Views: 83
Reputation: 201428
In your situation, how about the following modification?
function sample() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var formS = ss.getSheetByName("Form");
var dataS = ss.getSheetByName("Data");
var values = [
...formS.getRange("C7:C8").getValues().flat(),
formS.getRange("D9").getValue(),
...formS.getRange("B13:I23").getValues().flat()
];
dataS.appendRow(values);
}
However, I must continue it until row 23.
, I used B13:I23
.Upvotes: 2