简体   繁体   English

如何引用excel命名范围内的单元格?

[英]How do I reference a cell within excel named range?

For example, I have a named range A10—A20 as Age ;例如,我有一个命名范围 A10—A20 作为Age how do I get Age[5] which is same as A14.我如何获得与 A14 相同的Age[5]

I can write " =A14 " but I did like to write " =Age$5 " or something similar.我可以写“ =A14 ”,但我确实喜欢写“ =Age$5 ”或类似的东西。

您可以使用 Excel 的Index功能:

=INDEX(Age, 5)

"Do you know if there's a way to make this work with relative selections, so that the formula can be "dragged down"/applied across several cells in the same column?" “您知道是否有办法通过相对选择来实现这一点,以便公式可以“向下拖动”/应用于同一列中的多个单元格?”

To make such selection relative simply use ROW formula for a row number in INDEX formula and COLUMN formula for column number in INDEX formula.要使此类选择相对简单,只需将 ROW 公式用于 INDEX 公式中的行号,并将 COLUMN 公式用于 INDEX 公式中的列号。 To make this clearer here is the example:为了更清楚地说明这一点,这里是一个例子:

=INDEX(named_range,ROW(A1),COLUMN(A1))

Assuming the named range starts at A1 this formula simply indexes that range by row and column number of referenced cell and since that reference is relative it changes when you drag the the cell down or to the side, which makes it possible to create whole array of cells easily.假设命名范围从 A1 开始,这个公式只是按引用单元格的行和列号索引该范围,并且由于该引用是相对的,因此当您将单元格向下或向一侧拖动时,它会发生变化,这使得创建整个数组成为可能细胞容易。

There are a couple different ways I would do this:我有几种不同的方法可以做到这一点:

1) Mimic Excel Tables Using with a Named Range 1) 使用命名范围模仿 Excel 表格

In your example, you named the range A10:A20 "Age".在您的示例中,您将范围A10:A20命名为“年龄”。 Depending on how you wanted to reference a cell in that range you could either (as @Alex P wrote) use =INDEX(Age, 5) or if you want to reference a cell in range "Age" that is on the same row as your formula, just use:根据您希望如何引用该范围内的单元格,您可以(如@Alex P 所写)使用=INDEX(Age, 5)或者如果您想引用与“Age”范围内的单元格位于同一行你的公式,只需使用:

=INDEX(Age, ROW()-ROW(Age)+1)

This mimics the relative reference features built into Excel tables but is an alternative if you don't want to use a table.这模仿了 Excel 表格中内置的相关参考功能,但如果您不想使用表格,则是一种替代方法。

If the named range is an entire column, the formula simplifies as:如果命名范围是一整列,则公式简化为:

=INDEX(Age, ROW())

2) Use an Excel Table 2) 使用 Excel 表格

Alternatively if you set this up as an Excel table and type "Age" as the header title of the Age column, then your formula in columns to the right of the Age column can use a formula like this:或者,如果您将其设置为 Excel 表格并键入“年龄”作为年龄列的标题,那么您在年龄列右侧的列中的公式可以使用如下公式:

=[@[Age]]

I've been willing to use something like this in a sheet where all lines are identical and usually refer to other cells in the same line - but as the formulas get complex, the references to other columns get hard to read.我一直愿意在所有行都相同的工作表中使用类似的东西,并且通常引用同一行中的其他单元格 - 但随着公式变得复杂,对其他列的引用变得难以阅读。 I tried the trick given in other answers, with for example column A named as "Sales" I can refers to it as INDEX(Sales;row()) but I found it a bit too long for my tastes.我尝试了其他答案中给出的技巧,例如将 A 列命名为“Sales”,我可以将其称为INDEX(Sales;row())但我发现它对我的口味来说有点太长了。

However, in this particular case, I found that using Sales alone works just as well - Excel (2010 here) just gets the corresponding row automatically.但是,在这种特殊情况下,我发现单独使用Sales也同样有效 - Excel(此处为 2010)只会自动获取相应的行。

It appears to work with other ranges too;它似乎也适用于其他范围; for example let's say I have values in A2:A11 which I name Sales , I can just use =Sales*0.21 in B2:11 and it will use the same row value, giving out ten different results.例如,假设我在A2:A11有值,我将其命名为Sales ,我可以在B2:11使用=Sales*0.21 ,它将使用相同的行值,给出十个不同的结果。


I also found a nice trick on this page : named ranges can also be relative.我还在这个页面上发现了一个很好的技巧:命名范围也可以是相对的。 Going back to your original question, if your value "Age" is in column A and assuming you're using that value in formulas in the same line, you can define Age as being $A2 instead of $A$2, so that when used in B5 or C5 for example, it will actually refer to $A5.回到您最初的问题,如果您的值“Age”在 A 列中并假设您在同一行的公式中使用该值,您可以将 Age 定义为 $A2 而不是 $A$2,以便在使用时例如,在 B5 或 C5 中,它实际上会引用 $A5。 (The Name Manager always show the reference relative to the cell currently selected) (名称管理器始终显示相对于当前选定单元格的引用)

相对命名范围

Add a column to the left so that B10 to B20 is your named range Age.在左侧添加一列,以便 B10 到 B20 是您命名的范围年龄。

Set A10 to A20 so that A10 = 1, A11= 2,... A20 = 11 and give the range A10 to A20 a name eg AgeIndex .将 A10 设置为 A20,以便 A10 = 1, A11= 2,... A20 = 11 并为范围 A10 到 A20 命名,例如AgeIndex

The 5th element can be then found by using an array formula:然后可以使用数组公式找到第 5 个元素:

=sum( Age * (1 * (AgeIndex = 5) )

As it's an array formula you'll need to press Ctrl + Shift + Return to make it work and not just return.由于它是一个数组公式,因此您需要按Ctrl + Shift + Return使其工作,而不仅仅是返回。 Doing that, the formula will be turned into an array formula:这样做,公式将变成数组公式:

{=sum( Age * (1 * (AgeIndex = 5) )}

To read a particular date from range EJ_PAYDATES_2021 (index is next to the last "1")从范围 EJ_PAYDATES_2021 中读取特定日期(索引在最后一个“1”旁边)

=INDEX(PayDates.xlsx!EJ_PAYDATES_2021,1,1)  // Jan
=INDEX(PayDates.xlsx!EJ_PAYDATES_2021,2,1)  // Feb
=INDEX(PayDates.xlsx!EJ_PAYDATES_2021,3,1)  // Mar

This allows reading a particular element of a range [0] etc from another spreadsheet file.这允许从另一个电子表格文件读取范围 [0] 等的特定元素。 Target file need not be open.目标文件不需要打开。 Range in the above example is named EJ_PAYDATES_2021, with one element for each month contained within that range.上例中的范围命名为 EJ_PAYDATES_2021,该范围内包含每个月的一个元素。

Took me a while to parse this out, but it works, and is the answer to the question asked above.我花了一段时间来解析它,但它有效,并且是上面提出的问题的答案。

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

相关问题 excel 2003:如何从单元格引用命名范围? - excel 2003: How can I reference a named range from a cell? 如何在Excel命名范围中引用“子集”或单元格? - How do I reference a “subset” or cells in an Excel Named Range? 如何引用具有偏移量的命名范围中的单元格? - How can I reference a cell in a named range with an offset? Excel 2007:如何引用非连续命名范围? - Excel 2007: how do I reference a non-consecutive named range? EXCEL-如何查找具有特定内容的单元格,然后在另一个公式中引用该CELL(而不是其内容)? (内例) - EXCEL - How do I find a cell with specific content, and then reference that CELL (not its content) in another formula? (example within) 如何使用Excel公式引用从一个工作表到另一个工作表的单元格范围? - How do I reference a cell range from one worksheet to another using excel formulas? excel:我如何在一个单元格内排序? - excel: how do i sort within a cell? 对于Excel VBA中的每个循环,我如何引用公式中的单元格地址? - With For each loop in Excel VBA how do I reference the cell address within the formula? 参考动态命名范围取决于单元格值 Excel - Reference Dynamic Named Range dependent on cell value Excel 如何在Excel公式中子集命名范围? - How do I subset a named range in an Excel formula?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM