简体   繁体   English

Excel中如何使用R/C表示法将INDIRECT封装成INDEX?

[英]How to encapsulate INDIRECT into INDEX using R/C notation in Excel?

I created a range using INDIREKT, I added COL() to see how big this range is:我使用 INDIREKT 创建了一个范围,我添加了 COL() 来查看这个范围有多大:

=COL(INDIRECT("R1C1:R1C5"; 0))

As you can see, I'm using the R/C notation for row/colum adressing.如您所见,我使用 R/C 表示法进行行/列寻址。 The result is simply all numbers from 1 to 5 in the first row:结果只是第一行中从 1 到 5 的所有数字:

在此处输入图像描述

Now I'm just using the numbers to address letters from a string, like this:现在我只是使用数字来处理字符串中的字母,如下所示:

="_" & MID("HELLO"; COL(INDIRECT("Z1S1:Z1S5"; 0)); 1)

This works as expected and returns:这按预期工作并返回:

在此处输入图像描述

Now there's a random cell somewhere on the sheet, I named this cell "_H".现在工作表上某处有一个随机单元格,我将这个单元格命名为“_H”。 The cell just contains the letter H:该单元格仅包含字母 H:

在此处输入图像描述

I did this for E, L and O, too.我也为 E、L 和 O 做了这个。

Now I add a third row containing this.现在我添加第三行包含这个。

=INDEX(INDIRECT(A2);1;1)

Pulling this to the width of 5 columns the result is as expected:将其拉到 5 列的宽度,结果符合预期:

在此处输入图像描述

And here comes my problem: How to use the R/C notation?我的问题来了:如何使用 R/C 表示法? This comes into my mind:这进入我的脑海:

=INDIRECT("Z2S1"; 0)

This returns the correct value of row 2, column 1 aka A2.这将返回第 2 行第 1 列 aka A2 的正确值。 Which is _H.这是_H。 Now I put this into the INDEX formula, expecting that Excel takes the _H, use this as the address for INDEX and returns the value from 1;1 of this "name range":现在我将其放入 INDEX 公式中,期望 Excel 接受 _H,将其用作 INDEX 的地址并返回此“名称范围”的 1;1 的值:

=INDEX(INDIRECT("R2C1";0);1;1)

But the result is simply:但结果很简单:

在此处输入图像描述

When I remove the quotes, Excel is complaining, so this is not working:当我删除引号时,Excel 在抱怨,所以这是行不通的:

=INDEX(INDIRECT(R2C1;0);1;1)

(Apparently, because the Excel setting says I prefer A1-notation). (显然,因为 Excel 设置说我更喜欢 A1 表示法)。

But I wonder why it's not working, when I tell excel explicitly to use the R/C notation?但我想知道为什么当我明确告诉 excel 使用 R/C 表示法时它不起作用?

Well, it seems like Excel just takes the range and the value from R1C1 in this range - which is _R.好吧,看起来 Excel 只是取范围和 R1C1 的值在这个范围内 - 即 _R。 So I was trying around to make this column-argument "dynamic".所以我试图让这个专栏参数“动态”。 I know that this returns the column index for the whole range.我知道这会返回整个范围的列索引。

 =COL(INDIRECT("R1C1:R1C5";0))

This returns 1, 2, 3, 4 and 5 for the particular columns.这会为特定列返回 1、2、3、4 和 5。 So why not putting it into the formula above:那么为什么不把它放到上面的公式中呢:

 =INDEX(INDIRECT("Z2S" & COL(INDIRECT("R1C1:R1C5";0));0);1;COL(INDIRECT("R1C1:R1C5";0)))

This returns #VALUE as an error.这将返回 #VALUE 作为错误。

How to indirectly address a cell or even a range to get a value from a particular coordinate (using INDEX)?如何间接寻址单元格甚至范围以从特定坐标获取值(使用 INDEX)? I specifically need the R/C notation because I need to address ranges numerically (for example column 1 instead of column A and so on).我特别需要 R/C 表示法,因为我需要用数字来表示范围(例如第 1 列而不是 A 列等等)。

You can condense your solution - no `INDEX(X;1;1) needed:您可以压缩您的解决方案 - 不需要 `INDEX(X;1;1) :

=LET(word,"HELLO",
     singleCharacters,"_" & MID(word,SEQUENCE(1,LEN(word)),1),
     MAP(singleCharacters,LAMBDA(a,INDIRECT(a))))

Using LET makes it a bit more readable.使用LET使其更具可读性。

Ok, it's easier than I thought, Excel has this wonderful MAP formula:好的,这比我想象的要容易,Excel 有这个很棒的 MAP 公式:

=MAP(A2:E2; LAMBDA(a; INDEX(INDIRECT(a); 1; 1)))

Now every particular column points to the reference/range name and INDEX can use this, to get the value from R1/C1 of the particular named range.现在每个特定列都指向引用/范围名称,INDEX 可以使用它从特定命名范围的 R1/C1 中获取值。

This can even be more improved into a one-liner:这甚至可以改进为单行:

=MAP(SEQUENCE(1;LEN("HELLO")); LAMBDA(i; INDEX(INDIRECT("_" & MID("HELLO"; i; 1));1;1)))

I can put this everywhere I want, I just need to define the named ranges.我可以把它放在我想要的任何地方,我只需要定义命名范围。

Appreciation to @Ike who lead into the right direction.感谢引导正确方向的@Ike。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM