1

Basically the problem boils down to - how do I use a named reference/range within array in an Excel spreadsheet formula?

Example:

={"this","is","my","house"}

Produces 4 cells in one row with correct text

But this

={"this","is","my", House}

where House is a named range of a cell containing some text fails.

6
  • Untested: =HSTACK({"this","is","my"}, House) Commented Oct 15, 2022 at 19:55
  • Or if you don't have access to HSTACK =LET(a,{"this","is","my"},b,House,c,COUNTA(a),s,SEQUENCE(1,c+1),CHOOSE(IF(s<=c,1,2),a,b)) Again unable to test (named ranges can't be created in app version of Excel) Commented Oct 15, 2022 at 20:15
  • With HSTACK, no need for {} anyway. Commented Oct 15, 2022 at 21:12
  • Note... if you don't have access to HSTACK, you may not have access to LET() either. Commented Oct 16, 2022 at 0:19
  • This with HSTACK works, it occurred to me as I typed the question. This whole LET business and the logic behind it escapes me. Commented Oct 16, 2022 at 5:26

2 Answers 2

2

Your attempt failed, because of the array notation {}. An array, typed like that is limited to number values and/or text strings, for instance {"a",1,"b"}. A range can not be used inside an array notation neither can a named range.

To avoid the array notation and still get the array to include the named range you can make use of VSTACK or HSTACK who both create arrays or append arrays even.

In this case your array {"this","is","my"} can be used inside HSTACK and the named range House can be appended: =HSTACK({"this","is","my"},House)

This will give the desired result, but as HSTACK creates arrays by appending numerous values/ranges/arrays, we no longer need the {}:

Proper notation: =HSTACK("this","is","my", House)

Would be the proper notation.

If you would not have access to HSTACK, but have access to LET, you could use this little more complex solution:

=LET(a,{"this","is","my"},
     b,House,
     count_a,COUNTA(a),
     seq,SEQUENCE(1,count_a+1),
CHOOSE(IF(seq<=count_a,1,2),a,b))

First a (the text array) and b (the named range) are declared. Then count_a is declared, which counts the number of strings in array a (3). Then seq is declared to create a (horizontal) sequence from 1 to the count of strings in a (count_a) and adding 1 (resulting in {1,2,3,4}.

Then calculating if the sequence seq is smaller than or equal to the count of strings in a results in TRUE for the first 3 values of the sequence and false for the fourth: {TRUE,TRUE,TRUE,FALSE}. Using that in combination with IF (if TRUE 1, else 2) results in an array of {1,1,1,2}. Using that as the CHOOSE argument results in the 1st 3 times choosing values from a and the 4th time (the first) value of named range b.

Not using LET and SEQUENCE will result in a very unmanageable formula, which would require more work fixing the values within the formula then just typing them out, probably, but this would create the array in older Excel versions:

=CHOOSE( 
        IF(
           COLUMN($A$1: 
                  INDEX($1:$1048576,,COUNTA({"this","is","my"})+1))
 
           <=COUNTA({"this","is","my"}),
           1,
           2),
        {"this","is","my"},
        House)

Requires entered with ctrl+shift+enter and would appear as being one value only, because older Excel doesn't spill arrays into a range, but the array could be referenced inside a formula or as a named range.

Here COLUMN($A$1:INDEX($1:$1048576,,COUNTA({1,2,3}))) simulates the sequence function.

Sign up to request clarification or add additional context in comments.

1 Comment

Glad it helped you. I also added a non-LET version to demonstrate the benefit of using LET and to have a solution for older Excel users as well
1

If you have access to Excel O365:

With HSTACK, it would simply be =HSTACK("this","is","my",house).

House could be a single value or an array. If "House" is a named range {"A","B,"C"} then the HSTACK function above returns a 6 element array {"this","is","my","A","B,"C"}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.