Reputation: 4979
I want to union ranges from any Google spreadsheets.
Sheet1!A:A
{12, 131, 45}
Sheet2!A:A
{12, 131, 46}
The unknown function
=formula_for_union_range(Sheet1!A:A; Sheet2!:A:A)
should return
{12, 131, 45, 12, 131, 46}
How is it possible?
Upvotes: 133
Views: 175730
Reputation: 1
Another way I just tested for two sheets with same format but distinct headers
=TRANSPOSE({TRANSPOSE('sheet 1'!A2:E), TRANSPOSE('sheet2'!A2:E)})
Upvotes: 0
Reputation: 4979
And yet the question was about the script. I'm still successfully using the following code:
function unionRanges(e) {
var result = [];
var length = 0;
var i = 0;
try {
for (i = 0; i < arguments.length; i++)
length += arguments[i].length;
if (length > 3000) return '#BIGRANGE';
for (var i = 0; i < arguments.length; i++)
result = result.concat(arguments[i].filter(function (el) {
return el.join('').length > 0
}));
return result;
} catch (err) {
return JSON.stringify(err);
}
}
But, as noted above, it is easier to use {}
-notation.
={ Sheet1!A1:C10 ; Sheet2!A1:C34 }
Vertical concatenation
={ Range(Cols=N) ; Range(Cols=N) }
Horizontal concatenation
={ Range(Rows=M) , Range(Rows=M) }
It's possible to combine
={ { , , } ; { , , } }
Or something more hard
={{{;;},{;;}};{{;;},{;;}};{{;;},{;;}}}
Try something like this
={
{{ 1; 2; 3},{ 4; 5; 6}};
{{ 7; 8; 9},{10;11;12}};
{{13;14;15},{16;17;18}}
}
The internal horizontal concatenation is not required
={
{ 1; 2; 3},{ 4; 5; 6};
{ 7; 8; 9},{10;11;12};
{13;14;15},{16;17;18}
}
If your current locale supports ,
as an argument delimiter thnen you should use ;
for a vertical concatenation and ,
for a horizontal concatenation.
Otherwise your argument delimiter is ;
and you have to use ;
and \
(without spaces), respectively.
'Data 1'!A1:C20
| Name | Date | Sum |
| Ethan | 3/4/2017 | 31 |
| Logan | 3/6/2017 | 62 |
| Brian | 3/26/2017 | 61 |
| ... | ... | ... |
'Data 2'!A1:C20
| Name | Date | Sum |
| Nathan | 3/30/2017 | 53 |
| Alyssa | 3/13/2017 | 72 |
| John | 3/24/2017 | 79 |
| Megan | 3/16/2017 | 10 |
| ... | ... | ... |
={'Data 1'!A1:C20;'Data 2'!A2:C20}
| Name | Date | Sum |
| Ethan | 3/4/2017 | 31 |
| Logan | 3/6/2017 | 62 |
| Brian | 3/26/2017 | 61 |
| ... | ... | ... |
| Nathan | 3/30/2017 | 53 |
| Alyssa | 3/13/2017 | 72 |
| John | 3/24/2017 | 79 |
| ... | ... | ... |
={TRANSPOSE('Data 1'!A1:C20),TRANSPOSE('Data 2'!A2:C20)}
| Name | Ethan | Logan | Brian | ... | Nathan | Alyssa | John |
| Date | 3/4/2017 | 3/6/2017 | 3/26/2017 | ... | 3/30/2017 | 3/13/2017 | 3/24/2017 |
| Sum | 31 | 62 | 61 | ... | 53 | 72 | 79 |
More about this How to concatenate ranges in Google spreadsheets
Upvotes: 36
Reputation: 1
in 2024 C.E. for 1 column (as per your question) you can use:
=TOCOL({Sheet1!A:A; Sheet2!:A:A}; 1)
or longer:
=TOCOL(VSTACK(Sheet1!A:A; Sheet2!:A:A); 1)
1
indicates to remove blank cells
for less confusion between two major locale syntaxes when creating arrays, functions HSTACK
and VSTACK
were added, so:
=HSTACK(A1:C10; D3:F12; C2:C11)
instead of not knowing which of these to use:
={A1:C10, D3:F12, C2:C11}
={A1:C10\ D3:F12\ C2:C11}
next we have CHOOSECOLS
and CHOOSEROWS
if, for example, we need only A and C column:
=CHOOSECOLS(A:C; 1; 3)
and even WRAPCOLS
and WRAPROWS
can be useful for construction of 2D arrays, for example:
=WRAPROWS(TOROW(A2:D10; 1); 3; )
Upvotes: 1
Reputation: 3929
The FLATTEN
function is ideal for this.
=UNIQUE(FLATTEN(Sheet1!A:A, Sheet2!A:A))
Upvotes: 1
Reputation: 6039
At first when I tried ={Sheet1!A:A; Sheet2!A:A}
, I thought it didn't work because I could only see results from the first sheet. Turned out it was including all the blank cells too!
To filter out blank and empty cells while preserving duplicates (unlike =UNIQUE
) and without repeating yourself (unlike =FILTER()
), you can use =QUERY()
, like so:
=QUERY(
{March!A1:Z; April!A2:Z; May!A2:Z},
"select * where Col1 != '' and Col1 is not null",
0)
(Note that I am including the header row from the first sheet, and omitting it from the other sheets).
If your sheets don't contain cells with empty text, you can omit Col1 != '' and
.
Upvotes: 7
Reputation: 418
Suppose you have:
A B C D E F
1: 1 2 3 4 5 6
It's possible to concatenate slices as either rows or columns.
For additional columns (same row), use a comma. ={$A1:$C1,$D1:$F1}
yields:
1 2 3 4 5 6
For additional rows (same columns), use a semicolon. ={$A1:$C1;$D1:$F1}
yields:
1 2 3
4 5 6
Upvotes: 2
Reputation: 2915
If you want to union sheets and exclude rows with empty cells use the FILTER function in your formula:
=FILTER({Sheet1!A:A;Sheet2!A:A}, {Sheet1!A:A;Sheet2!A:A}<>"")
Upvotes: 3
Reputation: 1269
You can merge them into 1 column then get the unique values. Check the following formula:
=UNIQUE({Sheet1!A:A;Sheet2!A:A})
Upvotes: 117
Reputation: 17752
Although a script can do this easily, I recommend using regular spreadsheet formulas, e.g.
=transpose(split(join(";";Sheet1!A:A)&";"&join(";";Sheet2!A:A);";"))
To remove duplicates, just wrap it in a unique
formula:
=unique(transpose(...))
And to sort... =sort(...)
Upvotes: 21