Reputation: 29
I am writing a Google Apps Script for a Google Sheet and I want to select from a range of columns but exclude several columns in the middle.
I have a sheet resembling
+-------+-----+--------+--------+-------+
| Name | Age | Height | Income | State |
+-------+-----+--------+--------+-------+
| Bob | 23 | 185 | 50000 | OH |
| Jim | 35 | 160 | 23000 | HI |
| Frank | 24 | 142 | 44565 | CA |
| Tom | 24 | 155 | 23758 | NY |
+-------+-----+--------+--------+-------+
And I want to select the first two columns and the last column like so
+-------+-----+-------+
| Name | Age | State |
+-------+-----+-------+
| Bob | 23 | OH |
| Jim | 35 | HI |
| Frank | 24 | CA |
| Tom | 24 | NY |
+-------+-----+-------+
sheet.getRange()
works well enough getting a continuous range but what is the most compact way to combine two ranges with the same number of rows?
Upvotes: 1
Views: 6045
Reputation: 1
the most simple (and faster than QUERY
) is to use FILTER
or ARRAYFORMULA
like:
=ARRAYFORMULA({A:B, E:E})
=FILTER({A:B, E:E}, A:A<>"")
Upvotes: 1
Reputation: 59485
If Name
is in A1, I suggest:
=query(A:E,"select A,B,E")
or copy/paste the entire table and delete the surplus columns.
Upvotes: 1