Reputation: 49
I cant seem to figure out how to put this script to skip column L
. I tried many different varieties but all result in error. I hope somebody with more experience can shed light. I need I:K
and M:O
without L
.
sheet1.getRange("I1:O"+sheet1.getLastRow()).getValues()
Upvotes: 3
Views: 1928
Reputation: 27350
Another approach:
const array = sheet1.getRange('I1:O'+sheet1.getLastRow()).getValues();
array.forEach(a => a.splice(3, 1));
In more detail, 3
is chosen because, starting from 0
, L
is at the third position: I, J, K, L
.
Code snippet:
function myFunction() {
const ss = SpreadsheetApp.getActive();
const sheet1 = ss.getSheetByName('Sheet1');
const array = sheet1.getRange('I1:O'+sheet1.getLastRow()).getValues();
array.forEach(a => a.splice(3, 1));
console.log(array);
}
Upvotes: 2
Reputation: 201428
As a simpl modification, how about the following modification?
sheet1.getRange("I1:O"+sheet1.getLastRow()).getValues()
sheet1.getRange("I1:O"+sheet1.getLastRow()).getValues().map(([i,j,k,,m,n,o]) => [i,j,k,m,n,o]);
or
sheet1.getRange("I1:O"+sheet1.getLastRow()).getValues().map(([i,j,k,,...mno]) => [i,j,k,...mno]);
Upvotes: 4