Google Sheets: How do I create an array from a range, adding a column with a constant literal value in every row?

Viewed 2218

I want to make an array with several columns. The second and subsequent columns are specified as a range pulled from another sheet. The first column is a static constant, that is, every cell in the first column should have the very same literal string value, say 'foo'. I can't find the correct syntax. I'd have thought something like this would work:

={"foo", 'Other Sheet'!C2:F}

but I get "Function ARRAY_ROW parameter 2 has mismatched row size. Expected: 1. Actual: 999." Clearly "foo" needs to be "expanded" to a column with lots of rows. How do I do it, and where are tricks like this documented?

Maybe the answer to this question would give a start: How do I create an array containing a single column, every cell containing "foo", with the number of columns specified by a different range?

Here is an editable sheet illustrating the problem and the desired solution: https://docs.google.com/spreadsheets/d/17myzKVFN3SDQuubWNdP-dFAbdvdlRbZFkjRpLi2Fas8/edit?usp=sharing The exact question is this: what formula can I put in cell B9 of Sheet1 to get the current appearance of Sheet1? Notice that I don't know in advance how many rows there are in 'Other Sheet'. It's OK to assume that all rows of Other Sheet have a nonblank value in column C.

1 Answers

You can loop with an arrayformula and assign them to the first column, ending the array with the same size:

={ARRAYFORMULA(if(len('Other Sheet'!C2:C),"foo",)),'Other Sheet'!C2:F}

enter image description here

Side note: that between the {}, if you put a comma ({expr1 , expr2}), the value will be side by side, and if you put a semicolon ({expr1 ; expr2}), the values will be one above the other.

Related