CHOOSE function: First Argument is "index_num" - Can I reference an Array??

jase71ds

Board Regular
Joined
Oct 23, 2006
Messages
137
Office Version
  1. 365
Platform
  1. Windows
Hi kind folks.
As I've been learning the CHOOSE function, I've fallen in love. It's such a humble, but powerful, little function.

The arguments (according to intelli-sense) are:
CHOOSE(index_num, value1, [value2], [value3], [value4],...)

The index_num argument can be a cell reference, but apparently only if the cell in reference is a single value (not an array)
Is there a way around this??

For example:
This is a valid formula: =CHOOSE( {1,2}, A1:A2, B1:B2 )

But, if D1 is set to {1,2}, and the formula is =CHOOSE( D1, A1:A2, B1:B2 ), it breaks, because D1 gets evaluated as "{1,2}" with the quotes!

It would work if D1 would be evaluated, sans the strings (quotes).
Is there a way to evaluate D1 and strip the quotes (")???
When evaluated, I need D1 to be parsed as literally {1,2}, not as "{1,2}"

Hope that made sense.
Maybe a shorter version of the question: How to evaluate a cell reference that is an array, as an actual array and not a string?
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
If D1 contains {1,2} then it is a string & not an array.
Why not put the two values into D1 & E1 & use
Excel Formula:
=CHOOSE( D1:E1, A1:A2, B1:B2 )
 
Upvote 0
Try the following . . .

1) First, define the following (Ribbon >> Formula tab >> Defined Names group >> Define Name) . . .

VBA Code:
Name:  ChooseValue

Refers to:  =EVALUATE('Sheet1'!$D$1)

2) Then, use the following formula . . .

VBA Code:
=CHOOSE(ChooseValue,A1:A2,B1:B2 )

Hope this helps!
 
Upvote 0
Why not put the two values into D1 & E1 & use
Excel Formula:
=CHOOSE( D1:E1, A1:A2, B1:B2 )
Thanks. Seems like that is what I will have to do.
I was hoping that a single cell could hand off an array value to a function - but it's not looking like that's possible (apart from VBA).
 
Upvote 0
Try the following . . .

1) First, define the following (Ribbon >> Formula tab >> Defined Names group >> Define Name) . . .

VBA Code:
Name:  ChooseValue

Refers to:  =EVALUATE('Sheet1'!$D$1)

2) Then, use the following formula . . .

VBA Code:
=CHOOSE(ChooseValue,A1:A2,B1:B2 )

Hope this helps!
Thanks, but I should have mentioned that I was hoping for a non-VBA method.
 
Upvote 0
In that case, how about simply storing your array in a define name, and then referring to that name in your formula? So, for example . . .

VBA Code:
Name:  ChooseIndex

Refers to:  ={1,2}

Then your formula would be . . .

VBA Code:
=CHOOSE(ChooseIndex,A1:A2,B1:B2)
 
Upvote 0
In that case, how about simply storing your array in a define name, and then referring to that name in your formula? So, for example . . .

VBA Code:
Name:  ChooseIndex

Refers to:  ={1,2}

Then your formula would be . . .

VBA Code:
=CHOOSE(ChooseIndex,A1:A2,B1:B2)
Ohhh. That's an interesting approach!
Thanks, I'll look into it.
 
Upvote 0
I was hoping that a single cell could hand off an array value to a function
Assuming the string in D1 is something you are creating then could you leave out the curly brackets and just have "1,2" there?

Then since you have MS 365 you either will have, or will 'sometime' have, the new TEXTSPLIT function and you could use the formula in F1 below. If you do not have the TEXTSPLIT function yet then you could use the formula in I1.

If D1 must include the curly brackets then see the corresponding options in the bottom section.

jase71ds.xlsm
ABCDEFGHIJ
1ac1,2acac
2bdbdbd
3
4
5{1,2}acac
6bdbd
Sheet1
Cell Formulas
RangeFormula
F1:G2F1=CHOOSE(TEXTSPLIT(D1,","),A1:A2,B1:B2)
I1:J2I1=CHOOSE(TRANSPOSE(FILTERXML("<p><c>"&SUBSTITUTE(D1,",","</c><c>")&"</c></p>","//c")),A1:A2,B1:B2)
F5:G6F5=CHOOSE(TEXTSPLIT(MID(D5,2,LEN(D5)-2),","),A1:A2,B1:B2)
I5:J6I5=CHOOSE(TRANSPOSE(FILTERXML("<p><c>"&SUBSTITUTE(MID(D5,2,LEN(D5)-2),",","</c><c>")&"</c></p>","//c")),A1:A2,B1:B2)
Dynamic array formulas.
 
Upvote 0
Peter,
I am on MS 365, but it appears that I don't yet have TEXTSPLIT. I know that my company is on the delayed roll-out, so I'm not sure when I'll get it.
The FILTERXML hurts my simple brain.
I've got a solution that is working. But I'll admit, I'd really like to be able to pass the values of a single cell, to a formula as an array.
But for now, it's working.
Thanks very much for your time. I'll re-visit this when I get the latest MS 365 Corporate update - probably won't be too much longer.
Jase.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top