EXCEL: Array in a cell. How to get the array back?

℡╲_俬逩灬. 提交于 2020-01-04 02:17:07

问题


Let's say I have in B2 the formula =ROW(A1:A3). This formula gives an array of {1;2;3}. Because a cell only holds one value, cell B2 displays a value of 1. Any place in the worksheet, the formula =B2 gives 1, not the array. Yet, Excel still remembers the array because the formula is still in B2.

Is there any way to get the array back so it, the whole array, not its individual elements, can be used for further manipulation? I'm looking for something like OPERATION(B2) = {1;2;3}. For example, SUMPRODUCT(OPERATION(B2)) = SUMPRODUCT(ROW(A1:A3)) = 6.


回答1:


As a workaround, you can store your formula in Name Manager, e.g.:

Then you can use it as a reference in Excel formulas, like =INDEX(Rows,2,1):




回答2:


Just to try and clarify this, arrays in Excel before the September 2018 update for Office 365 don't self-expand like they do in Google sheets, so if you put an array into a single cell you just get the first element of the array (see column A for example).

If you want to enter the array directly into the sheet, you have to select the cells you want it to occupy (say B2:B4) and enter it as an array formula (see column B) using CtrlShiftEnter

You can still use the array in another formula as long as it's expecting an array - e.g. with sumproduct you get the correct total, 6 (see column C).

=SUMPRODUCT(ROW(A1:A3))

Unfortunately this doesn't always work without entering the whole formula as an array formula (see column D).

=SUM(ROW(A1:A3))

EDIT

@JvDV is correct, you don't always get the first element of an array expression entered into a single cell - see this reference for explanation of the implicit intersection mechanism.




回答3:


I realize that this is not the answer to the OP's question as they do not have the latest Office 365. I put this here for those who come later and do have it.


With the latest Office 365 with Dynamic array formulas this problem is now gone.

Putting =ROW(1:3) or the equivalent dynamic array formula =SEQUENCE(3) Excel will spill the array down automatically without the need of Ctrl-Shift-Enter:

And now one can refer to the array by only refering to A1 by putting # after the reference:

=SUM(A1#)

Then no matter how the array in A1 changes the other formula does not need to be changed.

The caveat is that the formula in A1 needs the room to spill down. If there is a cell that has anything in it that resides in the spill down array it will return an error.



来源:https://stackoverflow.com/questions/59544078/excel-array-in-a-cell-how-to-get-the-array-back

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!