Excel:从固定列获取相对行值的最佳方法是什么?
以下公式将始终返回下一行第 4 列 (D) 的值。
=INDIRECT("R[1]C[" & 4-COLUMN() & "]",FALSE)
有没有更好的方法来达到相同的结果?
The following formula will always return the value of the 4th column (D) of the next row.
=INDIRECT("R[1]C[" & 4-COLUMN() & "]",FALSE)
Is there a better way to achieve the same results?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
类似的,但更简洁且更容易阅读(恕我直言)的是 A1 寻址风格:
Similar, but less wordy and easier to read (IMHO), is the A1 style of addressing:
在复制和粘贴时,在列字母或行号前面放置“$”字符将锁定它。
例如:
Putting a '$' character in front of a column letter or row number will lock it down when you copy and paste.
Eg:
取决于你所说的更好:-)
如果你的意思是更短/更简单和A1风格,那么shoover的答案很好:
=INDIRECT("$D"&ROW()+1)
如果你喜欢R1C1 风格(恕我直言,更容易阅读;-)),那么一个更短/更简单/更快的解决方案是:
=INDIRECT("R[1]C4",)
但是,如果您追求最快解决方案,或者只是更喜欢非易失性的解决方案,那么命名公式是可行的方法:
定义一个名称,例如
Col4Down1
,并将其值设置为:=INDEX(!$D:$D,ROW()+1)
放置以下公式在单元格中获得所需的结果:
=Col4Down1
有效,是因为在命名公式中使用 bang 运算符
!
时存在一个鲜为人知的怪癖。当您不指定工作表名称时,!$D:$D
始终引用第四列,无论列删除/插入。将其视为绝对绝对寻址。最后,兰斯·罗伯茨的答案虽然稳定,但也存在一些问题。正如他提到的,它只能在某些预先确定的行中起作用。其次,插入/删除 AD 中的任何列或上面的任何行都会破坏它。修改它以修复这些导致以下内容(如果输入单元格 B2):
=INDEX(B:B:2:2,ROW()+1,4)
或者如果您更喜欢 R1C1 样式并且已将您的电子表格设置为使用此样式:
=INDEX(R:C,ROW()+1,4)
Depends what you mean by better :-)
If you mean shorter/simpler and A1 style, then shoover's answer is fine:
=INDIRECT("$D"&ROW()+1)
If you prefer R1C1 style (easier to read IMHO ;-) ) then an even shorter/simpler/faster solution is:
=INDIRECT("R[1]C4",)
However, if you're after the fastest solution, or just simply prefer a non-volatile one, then a Named Formula is the way to go:
Define a Name, say
Col4Down1
, and set its value to:=INDEX(!$D:$D,ROW()+1)
Place the following formula in a cell to get the desired result:
=Col4Down1
This works because of a little known quirk when using the bang operator
!
in a Named Formula. When you don't specify a sheetname,!$D:$D
always refers to the fourth column irrespective of column deletions/insertions. Think of it as absolute-absolute addressing.Finally, Lance Roberts' answer, whilst being non-volatile, suffers from a couple of problems. As he mentions, it will only work in certain, predetermined, rows. Secondly, insertion/deletion of any columns from A-D, or of any rows above, will break it. Modifying it to fix these leads to the following (if entered into cell B2):
=INDEX(B:B:2:2,ROW()+1,4)
or if you prefer R1C1 style and have set your spreadsheet to use this style:
=INDEX(R:C,ROW()+1,4)
如果您知道范围,这将起作用:
This will work if you know the range: