简体   繁体   English

Excel Vlookup与单元格引用

[英]Excel Vlookup with cell reference

I have a cell range that I named "cell_range" in Excel. 我在Excel中有一个名为“ cell_range”的单元格区域。 I want to extract the fourth row and fifth column from this table. 我想从该表中提取第四行和第五列。 The formula, 公式,

=vlookup(4,cell_range,5) = vlookup(4,cell_range,5)

gives me the value I am looking for. 给我我想要的价值。

However, I also have the text "cell_range" in cell A1. 但是,我在单元格A1中也有文本“ cell_range”。 Instead of typing out "cell_range" in my formula, I want to reference "cell_range" indirectly by referencing cell A1. 我不想在公式中键入“ cell_range”,而是要通过引用单元格A1间接引用“ cell_range”。 The formula 公式

vlookup(4,A1,5) vlookup(4,A1,5)

is giving me a "#N/A" error. 给我一个“#N / A”错误。

How can I indirectly reference the table "cell_range" in my formula? 如何在公式中间接引用表“ cell_range”?

使用INDIRECT:

=VLOOKUP(4,INDIRECT(A1),5)

While you can use INDIRECT to perform this kind of stuff, I steer clear of it for reasons I've outlined at https://chandoo.org/wp/2014/03/03/handle-volatile-functions-like-they-are-dynamite/ 虽然您可以使用INDIRECT来执行此类操作,但出于我在https://chandoo.org/wp/2014/03/03/handle-volatile-functions-like-they-炸药/

In this particular case I'd use a lookup table and either CHOOSE or INDEX, as demonstrated in the screenshot below: 在这种特殊情况下,我将使用查找表以及CHOOSE或INDEX,如以下屏幕截图所示:

在此处输入图片说明

Note that you need to pre-specify your areas with my approach. 请注意,您需要使用我的方法预先指定您的区域。

Here's the syntax for CHOOSE 这是CHOOSE的语法

=CHOOSE(index_num,value1,value2,...) = CHOOSE(index_num,value1,value2,...)

Here's the translation from Microsoft-speak into Jeff-speak: 这是从微软说话到杰夫说话的翻译:

=CHOOSE(Which area do you want?, First area, Second area, ...) = CHOOSE(您想要哪个区域?,第一个区域,第二个区域,...)

If using a dropdown or a cell reference to provide the index_num argument, you simply use a lookup table that converts the output of the dropdown or cell input into an index number that tells CHOOSE which range from the list should be used. 如果使用下拉列表或单元格引用提供index_num参数,则只需使用查找表即可将下拉列表或单元格输入的输出转换为索引号,该索引号告诉CHOOSE应该使用列表中的哪个范围。

In this example, you're using this approach to choose which area on the spreadsheet to sum. 在此示例中,您正在使用这种方法来选择电子表格中要汇总的区域。 But CHOOSE and INDEX can be used to do a lot more than that. 但是CHOOSE和INDEX可以做的还不止这些。 For instance, you could use them to allow a user to dynamically pick which lookup table to use when doing a VLOOKUP. 例如,您可以使用它们来允许用户动态地选择执行VLOOKUP时要使用的查找表。 Or you could let the user dynamically pick which range in which sheet to user for some calculations do. 或者,您可以让用户动态选择要进行某些计算的用户工作表范围。 Very powerful stuff indeed! 确实功能非常强大!

This is a great alternative to the use of INDIRECT. 这是使用INDIRECT的绝佳选择。 Indirect is intuitively easy to use but I agree that users should stay clear of it. 间接在直观上易于使用,但我同意用户应避免使用它。 For workbooks with many sheets I suggest using a macro to list them all rather than manually creating a list of sheets. 对于具有很多工作表的工作簿,我建议使用宏将其全部列出,而不是手动创建工作表列表。 See https://www.automateexcel.com/vba/list-all-sheets-in-workbook/ 参见https://www.automateexcel.com/vba/list-all-sheets-in-workbook/

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

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