INDEX在使用ArrayFormula时的替代方法

huangapple go评论54阅读模式
英文:

INDEX Altirnative when using ArrayFurmula

问题

我知道你已经厌倦了阅读相同的内容,但这里还是内容:

要做的是创建一个动态/依赖下拉列表,而不使用应用脚本。

简单举个例子,B2 单元格具有来自范围 V2:Y2 的下拉列表,该范围会根据 A2 的值而变化。

我们可以使用以下公式根据 A2 的值更改范围 V2:Y2 中的值:

=IF(
	ISBLANK(A2), 
	, 
	TRANSPOSE(
		INDEX(
			$C$3:$D$6, 
			, 
			MATCH(A2,$C$2:$D$2)
		)
	)
)

使用填充手柄,我们可以将该公式复制到 V 列中的每个单元格,并自动更改引用。

问题 #1:

这个解决方案运行良好,但是如果添加了新行,它们将没有这个公式,必须手动添加。

解决方案 #1:使用 ArrayFormula

ArrayFormula 允许您将公式放在一个单元格中,它将运行并根据绝对/非绝对引用在多个单元格中填充公式的输出。

问题 #2:

ArrayFormula 不支持某些公式,如 INDEXIFS,所以大多数人倾向于使用不太规范的解决方法,比如使用 VLOOKUP

VLOOKUP 可以执行 INDEX 可以执行的操作,但问题是据我所知,VLOOKUP 不能像 INDEX 一样填充多个单元格。

解决方法 #1:使用 HLOOKUP

我知道我刚才说了VLOOKUP的不好,现在我正在使用它的对应项,但这是不同的,它不是垂直查找,而是水平查找 - 在这里插入大脑爆炸的gif-

我只是使用HLOOKUP而不是VLOOKUP,因为我的数据是水平的,但思想是一样的,我们可以做INDEX做的事情,但每次只能处理一个单元格。

因此,使用以下公式:

=ARRAYFORMULA(
	IF(
		ISBLANK($A$2:$A), 
		, 
		IF(
			ISERROR(HLOOKUP($A$2:$A,$C$2:$D$6,COLUMN(O:O)-13)), 
			, 
			HLOOKUP($A$2:$A,$C$2:$D$6,COLUMN(O:O)-13)))
)

我们可以使用填充手柄将该公式复制到第 2 行中的每个单元格,并自动更改引用。

最后一个问题:

现在我们有与以前相同的问题,但只是更改了轴。理想情况下,我想要一个公式,可以填充两个轴中的单元格。

英文:

I know you're tired of reading the same line but here it is anyway:<br>
What I'm trying to do is make a Dynamic/Dependent Dropdown List without Using Apps Scripts.

Just to keep it short with an example, B2 Cell has a dropdown from range V2:Y2 and that range changes dependant on A2 Value.

INDEX在使用ArrayFormula时的替代方法

We can make the values in the range V2:Y2 change based on the value of A2 using the formula

=IF(
	ISBLANK(A2), 
	, 
	TRANSPOSE(
		INDEX(
			$C$3:$D$6, 
			, 
			MATCH(A2,$C$2:$D$2)
		)
	)
)

Using the Fill Handle we can copy the formula onto every cell in V Column and automatically change the references appropriately.

INDEX在使用ArrayFormula时的替代方法

PROBLEM #1:<br>
This solution works fine BUT if any new rows are added, they won't have the Formula and it have to be added manually.

SOLUTION #1: Using ArrayFormula.<br>
ArrayFormula Allows you to put your formula in One Cell and it would run and populate Multiple Cells with the Formula's Output depending on the Absolute/Non-Absolute References.

PROBLEM #2:<br>
ArrayFormula hates certain Formulas like INDEX and IFS, so most people tend to use dirty workarounds like using VLOOKUP<br>
INDEX在使用ArrayFormula时的替代方法<br>
VLOOKUP can do what INDEX can but the problem is as far as I know VLOOKUP cannot populate Multiple Cells like INDEX can.

WORK AROUND #1: Using HLOOKUP.<br>
I know I was just talking crap about VLOOKUP and now I'm using its counterpart But this is Different, Instead of looking Vertically, it looks Horizontally -Insert brain explosion gif here-<br>

I'm only using HLOOKUP instead of VLOOKUP Because my data is horizontal but the idea is the same, we can do what INDEX Does but only 1 Cell at a time.<br>
So Using this formula:<br>

=ARRAYFORMULA(
	IF(
		ISBLANK($A$2:$A), 
		, 
		IF(
			ISERROR(HLOOKUP($A$2:$A,$C$2:$D$6,COLUMN(O:O)-13)), 
			, 
			HLOOKUP($A$2:$A,$C$2:$D$6,COLUMN(O:O)-13))))

INDEX在使用ArrayFormula时的替代方法

We can use the Fill Handle to copy the formula onto every cell in 2 Row and automatically change the references appropriately.

INDEX在使用ArrayFormula时的替代方法

LAST PROBLEM:<br>
Now we have the same problem As before but we just changed the Axis.<br>
Ideally, I want to put one formula that can papulate cells in both Axes.

答案1

得分: 1

你可以尝试将这个公式放在Cell O2V2,看看效果如何...

=byrow(A2:A,lambda(z,if(z="","",transpose(filter(C3:D7,C2:D2=z))))

英文:

You may try this in Cell O2 or V2 perhaps and see how it goes...

=byrow(A2:A,lambda(z,if(z=&quot;&quot;,,transpose(filter(C3:D7,C2:D2=z)))))

huangapple
  • 本文由 发表于 2023年2月23日 23:20:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/75546809.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定