Make array with reference (no macro)

gifariz

Board Regular
Joined
May 2, 2021
Messages
128
Office Version
  1. 365
Platform
  1. Windows
As we know, the new excel release is super awesome with its array range and lambda function (along with other functions to work on array/lambda).
One problem that still makes me uncomfortable is making an array with reference.

We can make normal array as ={1,2,3;4,5,6}. But apparently we cannot make array with reference ={A1,C1,E1;A2:C2}.
Now I am still using this inelegant way to make array with reference =MAKEARRAY(2,3,LAMBDA(r,c,IF(r=1,IF(c=1,A1,IF(c=2,C1,IF(c=3,E1),INDEX(A2:C2,1,c))))

Is there simpler way to make array with reference?
(No macro)
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Try this (where the 1, 3 and 5 are the column numbers for Columns A, C and E)...

=INDEX(1:2,{1;2},{1,3,5})
 
Upvote 0
Actually, restricting the range for the INDEX function's first argument is probably better...

=INDEX(A1:E5,{1;2},{1,3,5})
 
Upvote 0
Try this (where the 1, 3 and 5 are the column numbers for Columns A, C and E)...

=INDEX(1:2,{1;2},{1,3,5})
Thank you. That works on above problem, but my example seems not quite general.
What if the reference is very far, and is dynamic array (size are changing)?

Here is another sample problem ={A1;AZ5#;TRANSPOSE(C50#)} where AE5# & C50# are dynamic arrays and different size, spanning vertical and horizontal respectively.
I cannot think of a way to do this with INDEX.

Actually, restricting the range for the INDEX function's first argument is probably better...

=INDEX(A1:E5,{1;2},{1,3,5})
Yes true, speed matters also.
 
Upvote 0
this will get you there, but it's not ideal if your dataset is much larger than this and you're pulling data from multiple rows/columns.

=VSTACK(CHOOSECOLS(A1:E1,1,3,5),CHOOSECOLS(A2:C2,1,2,3))

edit: never mind. I just read your second comment, and this will not address this at all.
 
Last edited:
Upvote 0
=IFERROR(VSTACK(A1,AZ5#,TRANSPOSE(C50#)),"")? You'd basically be nesting VSTACK and HSTACK for ; and , respectively, as compared to stacking arrays in google sheets, if that's the comparison you're making.
 
Upvote 0
Solution
=IFERROR(VSTACK(A1,AZ5#,TRANSPOSE(C50#)),"")? You'd basically be nesting VSTACK and HSTACK for ; and , respectively, as compared to stacking arrays in google sheets, if that's the comparison you're making.
Right, I have been doing this since the release of VSTACK and HSTACK functions. My question was posted before those functions exist. Thanks tho
 
Upvote 0
Right, I have been doing this since the release of VSTACK and HSTACK functions. My question was posted before those functions exist. Thanks tho
Oops, didn't notice that I accidentally replied to a year old thread. I blame Rich937 for the bump 😅
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,155
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